-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.py
140 lines (104 loc) · 3.7 KB
/
checker.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
#!/usr/bin/python
# coding=utf-8
__author__ = 'shipko'
import socket
import pyexiv2
import urllib, hashlib, requests, re, random
from sys import argv, exit, stderr
import os
PORT=2205
def check(hostname):
try:
response = os.system("ping -c 1 " + hostname + " > /dev/null 2>&1") # -t 3 нужно ли?
if response != 0:
print("Host unreachable")
return 104
welcome = urllib2.urlopen("http://" + hostname + ":" + str(PORT)).read()
if "Welcome" not in welcome:
print("Welcome message not found")
return 103
print("ok")
return 101
except:
print("Port unreachable")
return 104
def put(hostname, id, flag):
try:
response = os.system("ping -c 1 " + hostname + " > /dev/null 2>&1") # -t 3 нужно ли?
if response != 0:
print("Host unreachable")
return 104
mail = str(id) + "@yandex.ru"
password = hashlib.md5(str(id) + "verysibirctfhardhardpass")
r = requests.post('http://' + hostname + ":" + str(PORT)+ "/login",
data={ 'mail' : mail, 'password': password.hexdigest() }
);
cookie = {'connect.sid': r.cookies['connect.sid']}
# Attach tags in photo
r = requests.get('http://api-fotki.yandex.ru/api/top/')
urls = re.findall(r'href="([^"]*_XL)"', r.text)
url = urls[random.randint(1,len(urls))]
page = requests.get(url)
with open('/tmp/image.jpg', 'wb') as test:
test.write(page.content)
metadata = pyexiv2.ImageMetadata('/tmp/image.jpg')
metadata.read()
key = 'Exif.Image.Artist'
metadata[key] = pyexiv2.ExifTag(key, flag)
metadata.write()
data = { 'descr': '', 'geo': flag }
files = { 'photo': ('112.jpg',
open('/tmp/image.jpg', 'r'),
'image/jpeg'
) }
r = requests.post('http://' + hostname + ":" + str(PORT)+ "/add",
cookies=cookie,
data=data,
files=files
);
if "added" not in r.text:
print "Can't add photo"
return 103
return 101
except:
print("Error happend")
return 102
def get(hostname, id, flag):
try:
response = os.system("ping -c 1 " + hostname + " > /dev/null 2>&1") # -t 3 нужно ли?
if response != 0:
print("Host unreachable")
return 104
mail = str(id) + "@yandex.ru"
password = hashlib.md5(str(id) + "verysibirctfhardhardpass")
r = requests.post('http://' + hostname + ":" + str(PORT)+ "/login",
data={ 'mail' : mail, 'password': password.hexdigest() }
);
cookie = {'connect.sid': r.cookies['connect.sid']}
r = requests.get('http://' + hostname + ":" + str(PORT)+ "/profile",
cookies=cookie,
);
next_url = re.compile(r"photo/[a-z0-9]*").findall(r.text)[0]
r = requests.get('http://' + hostname + ":" + str(PORT)+ "/" + next_url,
cookies=cookie,
);
if flag in r.text:
print('ok')
return 101
else:
print('not ok')
return 102
except:
return check(hostname)
if __name__ == '__main__':
if len(argv) > 1:
if argv[1] == "check":
if len(argv) > 2:
exit(check(argv[2]))
elif argv[1] == "put":
if len(argv) > 4:
exit(put(argv[2], argv[3], argv[4]))
elif argv[1] == "get":
if len(argv) > 4:
exit(get(argv[2], argv[3], argv[4]))
exit(110)