-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·78 lines (65 loc) · 2.05 KB
/
configure
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
#!/bin/bash
# Configure script that tweaks shellcode per provided user options (for instance
# defining the host and port). This is a requirement for the exam.
cfg_err()
{
echo $@! >&2
exit 1
}
cfg_host()
{
echo -n 0x
echo $1|tr . '\n'|tac|while read n; do
printf "%02x" $n
done
}
cfg_nuls_host()
{
echo $1|tr . '\n'|grep -q "^0" || return
cfg_err "Host contains NUL bytes"
}
cfg_nuls_port()
{
printf "%04x" $1|grep -o ..|grep -q 00 || return
cfg_err "Port contains NUL bytes"
}
cfg_port()
{
echo -n 0x
printf "%04x" $1|grep -o ..|tac|tr -d '\n'
}
cfg_usage()
{
echo "${0##*/} [-h rhost] [-l lport] [-r rhost] [-s shellcode]" >&2
exit 1
}
while getopts "h:l:r:s:" ch; do
case $ch in
h) cfg_rhost="$OPTARG";; # Remote host used by the reverse shell.
l) cfg_lport="$OPTARG";; # Local host used by the bind shell.
r) cfg_rport="$OPTARG";; # Remote port user by the reverse shell.
s) cfg_shell="$OPTARG";; # Path to a generated shellcode.
*) cfg_usage;;
esac
done
shift $((OPTIND - 1))
cfg_lport="${cfg_lport-4242}" # Default to a local port of 4242/tcp.
cfg_rhost="${cfg_rhost-127.1.1.1}" # Default to a remote host of 127.1.1.1.
cfg_rport="${cfg_rport-4242}" # Default to a remote port 4242/tcp.
cfg_shell="${cfg_shell-0x01-bind/bind}" # Default to the bind shell, if exists.
cfg_nuls_port $cfg_lport || cfg_lport=`cfg_port $cfg_lport`
cfg_nuls_host $cfg_rhost || cfg_rhost=`cfg_host $cfg_rhost`
cfg_nuls_port $cfg_rport || cfg_rport=`cfg_port $cfg_rport`
echo "Using listening port: $cfg_lport"
echo "Using remote host: $cfg_rhost"
echo "Using remote port: $cfg_rport"
sed -e "s,PORT,$cfg_lport," 0x01-bind/*.in >0x01-bind/bind.asm
sed -e "s,HOST,$cfg_rhost," \
-e "s,PORT,$cfg_rport," \
0x02-reverse/*.in >0x02-reverse/reverse.asm
test -e "$cfg_shell" || cfg_err "Shellcode not found; not configuring encoder"
echo "Using shellcode: $cfg_shell"
cfg_shell=`asm-opcodes $cfg_shell`
cfg_shell=`echo -e $cfg_shell`
cfg_shell=`python 0x04-encoder/encoder.py "$cfg_shell"|tail -n1`
sed -e "s#SHELLCODE#$cfg_shell#" 0x04-encoder/*.in >0x04-encoder/decoder.asm