- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshellcode.sh
More file actions
Latest commit
106 lines (95 loc) · 2.92 KB
/
Copy pathshellcode.sh
File metadata and controls
106 lines (95 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
flag=$1
binaryFile=$2
currentFolder=${PWD}
functiongetShellcode {
# Get data from binary
foriin$(objdump -d $binaryFile|grep "^ "|cut -f2);do
shellcode=$shellcode'\x'$i
done
}
functionsaveShellcode {
rm -f $binaryFile"_shellcode.txt"
echo$shellcode>>$binaryFile"_shellcode.txt"
echo"Shellcode save into "$binaryFile"_shellcode.txt"
}
functioninjectShellcode {
shellcodeTestFile=$currentFolder"/Shellcode-Injectable-Projectshellcode.c"
shellcodeTestLine="4"
shellcode_escaped=$(echo"$shellcode"| sed -e 's/[\/&]/\\&/g')
code="char code[] =\"$shellcode_escaped\";"
sed -i "${shellcodeTestLine}s/.*/$code/""$shellcodeTestFile"
echo"Shellcode injected into "$currentFolder"/Shellcode-Injectable-Projectshellcode.c"
}
functionbuildShellcode {
gcc $currentFolder"/Shellcode-Injectable-Projectshellcode.c" -o $currentFolder"/Shellcode-Injectable-Projectshellcode" -fno-stack-protector -z execstack -no-pie
echo"Shellcode test program was build succesfuly into "$currentFolder"/Shellcode-Injectable-Projectshellcode"
}
functionrunShellcode {
echo"Executing shellcode "$currentFolder"/Shellcode-Injectable-Projectshellcode"
./Shellcode-Injectable-Projectshellcode
}
# Print in console
functionprintShellcode {
echo
echo'Shellcode extracted: '
echo
echo$shellcode
echo
}
functionprintHelp {
echo
echo'Usage: bash shellcode.sh [<options>] [<filename>]'
echo
echo' -e, --extract Extract shellcode from binary file and print in console'
echo' -s, --save Save shellcode string into a .txt file'
echo' -t, --test Inject shellcode string into shellcode.c source code, ready to compile'
echo' -tb, --testbuild Inject shellcode string and build shellcode.c'
echo' -tbr, --testbuildrun Inject shellcode string, build shellcode.c and run program'
echo
echo'Example:'
echo' > bash shellcode.sh -tbr ~/ASM/HelloWorld/Helloworld.asm'
echo
}
whiletrue;do
case"$flag"in
-h|--help)
printHelp
break
;;
-e|--extract)
getShellcode
printShellcode
break
;;
# Save shellcode into a .txt file
-s|--save)
getShellcode
saveShellcode
break
;;
# Save shellcode into shellcode.c file to test
-t|--test)
getShellcode
injectShellcode
break
;;
-tb|--testbuild)
getShellcode
injectShellcode
buildShellcode
break
;;
-tbr|--testbuildrun)
getShellcode
injectShellcode
buildShellcode
runShellcode
break
;;
*)
printHelp
break
;;
esac
done