forked from commixproject/commix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commix.py
147 lines (113 loc) · 3.74 KB
/
commix.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python
# encoding: UTF-8
"""
This file is part of commix (@commixproject) tool.
Copyright (c) 2015 Anastasios Stasinopoulos (@ancst).
https://github.com/stasinopoulos/commix
This program 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.
For more see the file 'readme/COPYING' for copying permission.
"""
import sys
import random
import httplib
import urllib2
import urlparse
from src.utils import menu
from src.utils import colors
from src.utils import update
from src.utils import version
from src.utils import install
from src.utils import settings
from src.core.requests import proxy
from src.core.requests import headers
from src.core.injections import controller
"""
The main function.
"""
def main():
try:
#Call the banner
menu.banner()
# Check python version number.
version.python_version()
#Check if defined "--version" option.
if menu.options.version:
version.show_version()
sys.exit(0)
#Check if defined "--update" option.
if menu.options.update:
update.updater()
sys.exit(0)
#Check if defined "--install" option.
if menu.options.install:
install.installer()
sys.exit(0)
# Check arguments
if len(sys.argv) == 1:
menu.parser.print_help()
print ""
sys.exit(0)
#Check if specified wrong injection technique
if menu.options.tech and menu.options.tech not in settings.AVAILABLE_TECHNIQUES:
print colors.BGRED + "(x) Error: Specified wrong injection technique!" + colors.RESET
sys.exit(0)
#Check if defined "--random-agent" option.
if menu.options.random_agent:
menu.options.agent = random.choice(settings.USER_AGENT_LIST)
#Check if defined "--url" option.
if menu.options.url:
sys.stdout.write(colors.BOLD +"(*) Checking connection to the target URL... " + colors.RESET)
sys.stdout.flush()
url = menu.options.url
# If URL not starts with any URI scheme, add "http://"
if not urlparse.urlparse(url).scheme:
url = "http://" + url
try:
request = urllib2.Request(url)
#Check if defined extra headers.
headers.do_check(request)
#print request.headers
response = urllib2.urlopen(request)
content = response.read()
print "[ " + colors.GREEN + "SUCCEED" + colors.RESET + " ]"
except urllib2.HTTPError, e:
print "[ " + colors.RED + "FAILED" + colors.RESET + " ]"
if e.getcode() == 500:
content = e.read()
sys.exit(0)
elif e.getcode() == 401:
print colors.BGRED + "(x) Error: Authorization required!" + colors.RESET + "\n"
sys.exit(0)
elif e.getcode() == 403:
print colors.BGRED + "(x) Error: You don't have permission to access this page." + colors.RESET + "\n"
sys.exit(0)
elif e.getcode() == 404:
print colors.BGRED + "(x) Error: The host seems to be down!" + colors.RESET + "\n"
sys.exit(0)
else:
raise
except urllib2.URLError, e:
print "[ " + colors.RED + "FAILED" + colors.RESET + " ]"
print colors.BGRED + "(x) Error: The host seems to be down!" + colors.RESET + "\n"
sys.exit(0)
except httplib.BadStatusLine, e:
print "[ " + colors.RED + "FAILED" + colors.RESET + " ]"
print e.line, e.message
pass
else:
print colors.BGRED + "(x) Error: You must specify the target URL." + colors.RESET + "\n"
sys.exit(0)
#Check if defined "--proxy" option.
if menu.options.proxy:
proxy.do_check(url)
# Launch injection and exploitation controller.
controller.do_check(url)
except (KeyboardInterrupt, SystemExit):
print ""
sys.exit(0)
if __name__ == '__main__':
main()
#eof