stuppid_bot

Spammer dmir.ru

Jun 22nd, 2013
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.79 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # данные от аккаунта
  3. email = '***'
  4. password = '***'
  5.  
  6. def parse_set_cookie(res):
  7.     q = {}
  8.     w = re.sub('; *expires=[^;]+', '', res.getheader('set-cookie'))
  9.     w = w.split(',')
  10.     for e in w:
  11.         r, t = e.split(';')[0].split('=', 1)
  12.         q[r.strip()] = t.strip()
  13.     return q
  14.  
  15. def build_cookie_string(cookie):
  16.     L = []
  17.     for k, v in cookie.items():
  18.         L.append(k + '=' + v)
  19.     return '; '.join(L)
  20.  
  21. # модуль mimetypes не может работать с кириллическими типами(например, "аудио/AMR") и падает
  22. mime_types = {
  23.     'bmp': 'image/bmp',
  24.     'gif': 'image/gif',
  25.     'jpg': 'image/jpeg',
  26.     'jpeg': 'image/jpeg',
  27.     'png': 'image/png'
  28. }
  29.  
  30. def multipart_form_data(boundary, fields, files=None):
  31.     L = ['']
  32.     for k, v in fields.items():
  33.         L.append('Content-Disposition: form-data; name="' + k + '"\r\n\r\n' + v + '\r\n')
  34.     if files:
  35.         for k, v in files.items():
  36.             f = open(v, 'rb')
  37.             data = f.read()
  38.             f.close()
  39.             filename = v.replace('\\', '/').split('/')[-1]
  40.             parts = filename.split('.')
  41.             extension = parts[-1].lower() if len(parts) > 1 else ''
  42.             content_type = mime_types[extension] if extension in mime_types else 'application/octet-stream'
  43.             L.append('Content-Disposition: form-data; name="' + k + '"; filename="' + filename + '"\r\nContent-Type: ' + content_type + '\r\n\r\n' + data + '\r\n')
  44.     return ('--' + boundary + '\r\n').join(L) + '--' + boundary + '--\r\n'
  45.  
  46. def upload_photo(src):
  47.     conn = httplib.HTTPConnection('dmir.ru')
  48.     boundary = str(uuid.uuid4())
  49.     post =  multipart_form_data(boundary, {}, {'file': src})
  50.     conn.request('POST', '/handlers/UpFileHandler.ashx?mode=add', post, {                                                                
  51.         'Cookie': build_cookie_string(cookie),
  52.         'Content-Type': 'multipart/form-data; boundary=' + boundary,
  53.     })
  54.     res = conn.getresponse()
  55.     o = res.read()
  56.     # js obj -> python dict
  57.     exec 'o=' +  re.sub('([a-z]+):', '"\\1":', o)
  58.     return o['file'] + ':' + str(o['size'])
  59.  
  60. def save_advertisment(keywords, country, city, adress, metro, location, rubric, sub_rubric, title, text, price, contacts, name, country_code, phone, comment, files):
  61.     post = {
  62.         '__EVENTTARGET': 'ctl00$ctl00$body$body$btnSave',
  63.         '__EVENTARGUMENT': '',    
  64.         '__VIEWSTATE': view_state,    
  65.         'ctl00$ctl00$body$SearchForm1$Keywords': '',    
  66.         'ctl00$ctl00$body$body$hiddenCountry': country,
  67.         'ctl00$ctl00$body$body$location$txtTown': city,
  68.         'ctl00$ctl00$body$body$location$txtAddress': adress,    
  69.         'ctl00$ctl00$body$body$location$hiddenMetro': metro,    
  70.         'ctl00$ctl00$body$body$location$hiddenTown': location,
  71.         'ctl00$ctl00$body$body$listRubrics': rubric,
  72.         'ctl00$ctl00$body$body$listChildRubrics': sub_rubric,
  73.         'ctl00$ctl00$body$body$txtName': title,
  74.         'ctl00$ctl00$body$body$txtNote': text,
  75.         'ctl00$ctl00$body$body$txtPrice': price,
  76.         'ctl00$ctl00$body$body$hiddenEditContacts': contacts,    
  77.         'ctl00$ctl00$body$body$txtFirstName': name,    
  78.         'ctl00$ctl00$body$body$hiddenCountryCode': country_code,
  79.         'ctl00$ctl00$body$body$txtPhone': phone,    
  80.         'ctl00$ctl00$body$body$txtComment': comment,    
  81.         'ctl00$ctl00$body$body$chAcceptAdm': 'on',
  82.         'ctl00$ctl00$body$body$chAcceptRules': 'on',
  83.         'files': ','.join(files),
  84.         'delFiles': '',    
  85.         'price': '',
  86.         'rubric': ''
  87.     }
  88.     post = urlencode(post)
  89.     # сохраняем объявление
  90.     conn = httplib.HTTPConnection('dmir.ru')
  91.     conn.request('POST', '/user/announcement/save.aspx', post, {
  92.         'Cookie': build_cookie_string(cookie),
  93.         'Content-Type': 'application/x-www-form-urlencoded'
  94.     })
  95.     res = conn.getresponse()
  96.     m = re.match('/user/announcement/add.aspx\?ok=1&id=\d+', res.getheader('location'))
  97.     print 'Объявление сохранено и ожидает проверки' if m else 'Ошибка при сохранении объявления'
  98.  
  99.  
  100. import socket, socks, httplib, re, os, uuid
  101. from urllib import urlencode
  102. socket.setdefaulttimeout(30)
  103. # можно использовать TOR для анонимной публикации объявлений
  104. # socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
  105. # socket.socket = socks.socksocket
  106. # авторизуемся
  107. conn = httplib.HTTPConnection('dmir.ru')
  108. post = 'email=' + email + '&password=' + password + '&rememberMe=true&mode=login&windowname=true'
  109. conn.request('POST', '/webservices/logon.ashx', post, {
  110.     'Content-Type': 'application/x-www-form-urlencoded'
  111. })
  112. res = conn.getresponse()
  113. cookie = parse_set_cookie(res)
  114. # на странице добавления объявления вешаются дополнительные cookie + имеется скрытое поле __VIEWSTATE
  115. conn = httplib.HTTPConnection('dmir.ru')
  116. conn.request('GET', '/user/announcement/add.aspx', '', {
  117.     'Cookie': build_cookie_string(cookie)
  118. })
  119. res = conn.getresponse()
  120. # _cookie = parse_set_cookie(res)
  121. # cookie.update(_cookie)
  122. data = res.read()
  123. m = re.search('id="__VIEWSTATE" value="([^"]+)', data)
  124. view_state = m.group(1)
  125. files = []
  126. files.append(upload_photo('uploads/V mask prize.jpg'))
  127. save_advertisment('', '138', '', '', '', '1', '87', '664', 'Продам хуйню', 'Ну как-то так', '15000', '', 'Иван Иванович Иванов', '7_138', '', '', files)
  128. save_advertisment('', '138', '', '', '', '1', '87', '664', 'Хуй, пизда, Джигурда', 'маму ебал', '', '', 'Иван Иванович Иванов', '7_138', '', '', files)
Advertisement
Add Comment
Please, Sign In to add comment