# needs python 2
import urllib
import urllib2
import time
import json
import random
# dove scrivono gli stronzi:
xmin = 95
xmax = 106
ymin = 316
ymaz = 323
offense=2 # 1 = defend first 2+ = attack more, proportionally to the number
delay_minutes=5 # MAKE SURE THIS IS >= the actual delay
protected = []
def get_target_color(x):
if(x>=95 and x<=106): return 3 # left border: black
if(y>=316 and y<=323): return 3 # first stripe: green
print "Build the Italy Flag"
print "Getting user agent list for anonymity (please wait)"
user_agent_list=list(set([ua for ua in urllib.urlopen("https://raw.githubusercontent.com/sqlmapproject/sqlmap/master/txt/user-agents.txt").read().splitlines() if not ua.startswith("#")]))
accounts = []
sessions = {}
print "For each account you want to use, enter it in like username:password"
print "When you're done, type 'done'"
user_input = ""
while (user_input != "done"):
user_input = raw_input("Account-> ")
if user_input.lower() != "done":
accounts.append(user_input)
opener = urllib2.build_opener()
opener.addheaders = [('User-Agent', random.choice(user_agent_list))]
for account in accounts:
username = account.split(":")[0]
password = account.split(":")[1]
data = urllib.urlencode({'op': 'login-main', 'user': username, 'passwd': password, 'api_type': 'json'})
resp = opener.open('https://www.reddit.com/api/login/'+urllib.quote(username), data).read()
sessions[username] = json.loads(resp)["json"]["data"]["cookie"]
print "Running Build the Italy Flag"
while True:
# Fill the void
for session in sessions.keys():
cookie = sessions[session]
x = random.randint(xmin,xmax)
y = ymin-1
target_color = get_target_color(x)
color = target_color
while color == target_color:
# Find a wrong square
y = y+random.randint(1,offense)
if (x,y) in protected:
continue
resp = opener.open("https://www.reddit.com/api/place/pixel.json?x="+str(x)+"&y="+str(y)).read()
try:
color = int(json.loads(resp)["color"])
except Exception, e:
#print "Exception"
#print resp
color = target_color
print "Found a non-flag color at", x, y
data = urllib.urlencode({'x': x, 'y': y, 'color': target_color})
newopener = urllib2.build_opener()
newopener.addheaders = [('User-Agent', random.choice(user_agent_list))]
newopener.addheaders.append(('Cookie', 'reddit_session='+cookie))
modhash = json.loads(newopener.open("https://reddit.com/api/me.json").read())["data"]["modhash"]
newopener.addheaders.append(('x-modhash', modhash))
next=newopener.open("https://www.reddit.com/api/place/draw.json", data).read()
print next
finalresp = newopener.open("https://www.reddit.com/api/place/pixel.json?x="+str(x)+"&y="+str(y)).read()
if session in finalresp:
print "Added successfully"
else:
print finalresp
time.sleep(delay_minutes*60+5)
Questo dovrebbe fare tutto il quadrato nero, ma a noi basterebbe eliminare solo i pixel blu dal quadrato