-
Notifications
You must be signed in to change notification settings - Fork 67
/
curl.py
145 lines (129 loc) · 4.29 KB
/
curl.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
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
"""
This file is part of the cintruder project, http://cintruder.03c8.net
Copyright (c) 2012/2016 psy <epsylon@riseup.net>
cintruder 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 version 3 of the License.
cintruder 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 cintruder; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
import pycurl
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
class CIntruderCurl(object):
"""
Class to control curl on behalf of the application.
"""
agent = 'Googlebot/2.1 (+http://www.google.com/bot.html)'
referer = '127.0.0.1'
proxy = None
ignoreproxy = None
def __init__(self, captcha="", ignoreproxy="", proxy=""):
"""
Class init
"""
self.handle = pycurl.Curl()
self.verbosity = 0
self.url = self.set_url(captcha)
self.captcha = StringIO()
self.proxy = self.set_proxy(ignoreproxy, proxy)
self.set_option(pycurl.SSL_VERIFYHOST, 0)
self.set_option(pycurl.SSL_VERIFYPEER, 0)
#self.set_option(pycurl.SSLVERSION, pycurl.SSLVERSION_SSLv3)
self.set_option(pycurl.COOKIEFILE, '/dev/null')
self.set_option(pycurl.COOKIEJAR, '/dev/null')
self.set_option(pycurl.NETRC, 1)
def set_url(self, url):
"""
Set the url.
"""
self.url = url
self.set_option(pycurl.URL, self.url)
return url
def set_agent(self, agent):
"""
Set the user agent.
"""
self.agent = agent
self.set_option(pycurl.USERAGENT, self.agent)
return agent
def set_referer(self, referer):
"""
Set the referer.
"""
self.referer = referer
self.set_option(pycurl.REFERER, self.referer)
return referer
def set_proxy(self, ignoreproxy, proxy):
"""
Set the proxy to use.
"""
self.proxy = proxy
self.ignoreproxy = ignoreproxy
if self.ignoreproxy == 1:
self.set_option(pycurl.PROXY, "")
else:
self.set_option(pycurl.PROXY, self.proxy)
return proxy
def set_verbosity(self, level):
"""
Set the verbosity level.
"""
self.set_option(pycurl.VERBOSE, level)
def set_option(self, *args):
"""
Set the given option.
"""
apply(self.handle.setopt, args)
def request(self):
"""
Perform a request and returns the payload.
"""
if self.agent:
self.set_option(pycurl.USERAGENT, self.agent)
if self.referer:
self.set_option(pycurl.REFERER, self.referer)
if self.proxy:
self.set_option(pycurl.PROXY, self.proxy)
if self.ignoreproxy:
self.set_option(pycurl.PROXY, "")
if self.url:
self.set_option(pycurl.URL, self.url)
self.set_option(pycurl.SSL_VERIFYHOST, 0)
self.set_option(pycurl.SSL_VERIFYPEER, 0)
self.handle.setopt(self.handle.WRITEFUNCTION, self.captcha.write)
try:
self.handle.perform()
print "[Info] Getting captcha...\n"
return self.captcha
except pycurl.error, error:
errno, errstr = error
print '\n[Error] Connection error!:', errstr, "\n"
return "exit"
def close(self):
"""
Close the curl handle.
"""
self.handle.close()
self.captcha.close()
def print_options(self):
"""
Print selected options.
"""
print "\n[-]Verbose: active"
print "[-]HTTP User Agent:", self.agent
print "[-]HTTP Referer:", self.referer
if self.ignoreproxy:
print "[-]Proxy:", "No proxy!"
else:
print "[-]Proxy:", self.proxy
print "[-]URL:", self.url, "\n"