forked from digitalocean/sample-python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
Latest commit
250 lines (207 loc) · 8.57 KB
/
Copy pathMain.py
File metadata and controls
250 lines (207 loc) · 8.57 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
#!/usr/bin/env python
####################################################
# #
# This bot only works with https://strawpoll.de. #
# #
####################################################
# Usage: Main.py [options]
#
# Options:
# -h, --help show this help message and exit
# -v VOTES, --votes=VOTES
# number of votes to give
# -s SURVEY, --survey=SURVEY
# id of the survey
# -t TARGET, --target=TARGET
# checkbox to vote for
# -f, --flush Deletes skipping proxy list
#
# EXAMPLE
#
# python Main.py -v 10 -s abbcw17 -t check3537987
#
#
try:
fromxml.domimportminidom
importxml.etree.cElementTreeasET
fromoptparseimportOptionParser
importsys
importos
exceptImportErrorasmsg:
print("[-] Library not installed: "+str(msg))
exit()
try:
importrequests
exceptImportError:
print("[-] Missing library 'requests'")
print("[*] Please install missing library with: pip install requests")
# Creator: Luis Hebendanz
classMain:
# SETTINGS
maxVotes=1
voteFor=""
surveyId=""
# GLOBAL VARIABLES
proxyListFile="https-proxy-list.xml"
saveStateFile="saveState.xml"
proxyTimeout=10# Seconds
currentProxyPointer=0
successfulVotes=0
def__init__(self):
try:
###
# Command line argument parser
###
parser=OptionParser()
parser.add_option("-v", "--votes", action="store", type="string", dest="votes",help="number of votes to give")
parser.add_option("-s", "--survey", action="store", type="string", dest="survey",help="id of the survey")
parser.add_option("-t", "--target", action="store", type="string", dest="target", help="checkbox to vote for")
parser.add_option("-f", "--flush", action="store_true", dest="flush",help="Deletes skipping proxy list")
(options, args) =parser.parse_args()
iflen(sys.argv) >2:
ifoptions.votesisNone:
print("[-] Number of votes not defined with: -v ")
exit(1)
ifoptions.surveyisNone:
print("[-] Survey id not defined with: -s")
exit(1)
ifoptions.targetisNone:
print("[-] Target to vote for is not defined with: -t")
exit(1)
try:
self.maxVotes=int(options.votes)
exceptValueError:
print("[-] Please define an integer for -v")
# Save arguments into global variable
self.voteFor=options.target
self.surveyId=options.survey
# Flush saveState.xml
ifoptions.flush==True:
print("[*] Flushing saveState.xml file...")
os.remove(self.saveStateFile)
# Print help
else:
print("[-] Not enough arguments given")
print()
parser.print_help()
exit()
# Read proxy list file
alreadyUsedProxy=False
xmldoc=minidom.parse(self.proxyListFile)
taglist=xmldoc.getElementsByTagName('para')
tagList2=None
# Check if saveState.xml exists and read file
ifos.path.isfile(self.saveStateFile):
xlmSave=minidom.parse(self.saveStateFile)
tagList2=xlmSave.getElementsByTagName("usedProxy")
# Print remaining proxies
iftagList2isnotNone:
print("[*] Number of remaining proxies in list: "+str(len(taglist) -len(tagList2)))
print()
else:
print("[*] Number of proxies in new list: "+str(len(taglist)))
print()
# Go through proxy list
fortagintaglist:
# Check if max votes has been reached
ifself.successfulVotes>=self.maxVotes:
break
# Increase number of used proxy integer
self.currentProxyPointer+=1
# Read value out of proxy list
tagValue=tag.childNodes[0].nodeValue
# Read in saveState.xml if this proxy has already been used
iftagList2isnotNone:
fortag2intagList2:
iftagValue==tag2.childNodes[0].nodeValue:
alreadyUsedProxy=True
break
# If it has been used print message and continue to next proxy
ifalreadyUsedProxy==True:
print("["+str(self.currentProxyPointer) +"] Skipping proxy: "+tagValue)
alreadyUsedProxy=False
continue
# Print current proxy information
print("["+str(self.currentProxyPointer) +"] New proxy: "+tagValue)
print("[*] Connecting... ")
# Connect to strawpoll and send vote
self.sendToWebApi('https://'+tagValue)
# Write used proxy into saveState.xml
self.writeUsedProxy(tagValue)
print()
# Check if max votes has been reached
ifself.successfulVotes>=self.maxVotes:
print("[+] Finished voting: "+str(self.successfulVotes))
else:
print("[+] Finished every proxy!")
exit()
exceptIOErrorasex:
print("[-] "+ex.strerror+": "+ex.filename)
exceptKeyboardInterruptasex:
print("[*] Saving last proxy...")
print("[*] Programm aborted")
exit()
defgetClientIp(self, httpProxy):
proxyDictionary= {"https": httpProxy}
rsp=requests.get("https://api.ipify.org/", proxies=proxyDictionary)
returnstr(rsp.text)
defwriteUsedProxy(self, proxyIp):
ifos.path.isfile(self.saveStateFile):
# Read file
tree=ET.parse(self.saveStateFile)
# Get <root> tag
root=tree.getroot()
child=ET.Element("usedProxy")
child.text=str(proxyIp)
root.append(child)
# Write to file
tree.write(self.saveStateFile, encoding="UTF-8")
else:
# Create <root> tag
root=ET.Element("article")
# Get element tree
tree=ET.ElementTree(root)
# Write to file
tree.write(self.saveStateFile, encoding="UTF-8")
# Now write defined entry into file
self.writeUsedProxy(proxyIp)
defsendToWebApi(self, httpsProxy):
try:
headers= \
{
'Host': 'strawpoll.de',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0',
'Accept': '*/*',
'Accept-Language': 'de,en-US;q=0.7,en; q=0.3',
'Referer': 'https://strawpoll.de/'+self.surveyId,
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest',
'Content-Length': '29',
'Cookie': 'lang=de',
'DNT': '1',
'Connection': 'close'
}
payload= {'pid': self.surveyId, 'oids': self.voteFor}
proxyDictionary= {"https": httpsProxy}
# Connect to server
r=requests.post('https://strawpoll.de/vote', data=payload, headers=headers, proxies=proxyDictionary, timeout=self.proxyTimeout)
json=r.json()
# Check if succeeded
if(bool(json['success'])):
print("[+] Successfully voted.")
self.successfulVotes+=1
returnTrue
else:
print("[-] Voting failed. This Ip already voted.")
returnFalse
exceptrequests.exceptions.Timeoutasex:
print("[-] Timeout")
returnFalse
exceptrequests.exceptions.ConnectionErrorasex:
print("[-] Couldn't connect to proxy")
returnFalse
exceptExceptionasex:
print(str(ex))
returnFalse
# Execute main
Main()