Advertisement
Guest User

Untitled

a guest
May 19th, 2017
2,691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. import requests
  2. import html
  3. import sys
  4. import os
  5. import random
  6.  
  7. class SteamBot:
  8. """A simple Steam bot class"""
  9. def __init__(self, api_key):
  10. # creates a session
  11. self.session = requests.session()
  12. # sets sessions headers
  13. self.headers = {'User-Agent': 'Mozilla/5.0'}
  14. self.session.headers.update(self.headers)
  15. # sets 2captcha api key
  16. self.api_key = api_key
  17.  
  18. def signup(self, username, password, email):
  19. while True:
  20. print('Attempting to create account: {}'.format(username))
  21. # gets valid captcha
  22. captcha = self.session.get('https://store.steampowered.com/join/refreshcaptcha/').json()
  23. print('Got captcha.')
  24. # gets captcha image
  25. image = self.session.get('https://store.steampowered.com/public/captcha.php', params=captcha).content
  26. print('Got captcha image.')
  27. # solves captcha
  28. print('Sending captcha to api...')
  29. response = self.__solve_captcha(image)
  30. print('Solved captcha.')
  31. # gets captcha gid
  32. captcha_gid = captcha['gid']
  33. # creates sign up headers
  34. headers = {'Referer': 'https://store.steampowered.com/join/?', 'X-Requested-With': 'XMLHttpRequest', 'X-Prototype-Version': '1.7'}
  35. # creates sign up payload
  36. payload = {'accountname': username, 'password': password, 'email': email, 'captchagid': captcha_gid, 'captcha_text': response, 'i_agree': '1', 'count': '10', 'it': '0'}
  37. # signs up on steam
  38. r = self.session.post('https://store.steampowered.com/join/createaccount/', data=payload, headers=headers)
  39. # validates account creation
  40. if r.json()['bSuccess']:
  41. # notifies user account has been created
  42. print('Account {} created.'.format(username))
  43. # gets steam id
  44. self.sId = self.session.cookies['steamLogin'].split('%7C%7C')[0]
  45. print('Got steam id: {}'.format(self.sId))
  46. # sets cookies for steam community
  47. self.session.cookies.set('steamCountry', self.session.cookies['steamCountry'], domain='steamcommunity.com', path='/')
  48. self.session.cookies.set('steamLogin', self.session.cookies['steamLogin'], domain='steamcommunity.com', path='/')
  49. self.session.cookies.set('steamLoginSecure', self.session.cookies['steamLoginSecure'], domain='steamcommunity.com', path='/')
  50. print('Successfully migrated cookies.')
  51. break
  52. else:
  53. # notify user of error
  54. print('There was a problem creating the account {}.'.format(username))
  55. # finds out error
  56. try:
  57. print(r.json()['details'])
  58. print('Retrying...')
  59. continue
  60. except KeyError:
  61. sys.exit('Account already exists.')
  62. break
  63.  
  64. def upload_avatar(self, filename):
  65. # gets cookies
  66. r = self.session.get('http://steamcommunity.com/profiles/{}/edit'.format(self.sId), params={'welcomed': '1'})
  67. # gets session id
  68. sessionid = r.text.split('g_sessionID = "')[-1].split('";')[0]
  69. print('Got session id.')
  70. # readys profile picture for upload
  71. avatar = {'avatar': ('avatar.png', open(filename, 'rb'), 'image/png')}
  72. print('Successfully read avatar.')
  73. # creates avatar payload
  74. payload = {'MAX_FILE_SIZE': '1048576', 'type': 'player_avatar_image', 'sId': self.sId, 'sessionid': sessionid, 'doSub': '1', 'json': '1'}
  75. # uploads profile picture
  76. r = self.session.post('http://steamcommunity.com/actions/FileUploader', data=payload, files=avatar)
  77. # validates upload
  78. if r.json()['success']:
  79. # notifies user avatar uploaded
  80. print('Uploaded avatar for: {}'.format(self.sId))
  81.  
  82. def make_private(self):
  83. # gets page for session id
  84. r = self.session.get('http://steamcommunity.com/profiles/{}/edit/settings'.format(self.sId))
  85. # gets session id
  86. sessionid = r.text.split('g_sessionID = "')[-1].split('";')[0]
  87. print('Got session id.')
  88. # creates make private payload
  89. payload = {'sessionID': sessionid, 'type': 'profileSettings', 'privacySetting': '1', 'commentSetting': 'commentfriendsonly', 'inventoryPrivacySetting': '2', 'inventoryGiftPrivacy': '1'}
  90. # posts make private data
  91. self.session.post('http://steamcommunity.com/profiles/{}/edit/settings'.format(self.sId), data=payload)
  92. # notifies user
  93. print('Profile {} has been made private.'.format(self.sId))
  94.  
  95. def join_group(self, name):
  96. # gets group page for session id
  97. r = self.session.get('http://steamcommunity.com/groups/{}'.format(name))
  98. # extracts session id
  99. sessionid = r.text.split('g_sessionID = "')[-1].split('";')[0]
  100. print('Got session id.')
  101. # creates join payload
  102. payload = {'action': 'join', 'sessionID': sessionid}
  103. # posts join group data
  104. self.session.post('http://steamcommunity.com/groups/{}'.format(name), data=payload)
  105. # notifies user
  106. print('Joined steam group: {}'.format(name))
  107.  
  108. def __solve_captcha(self, captcha):
  109. # creates captcha payload
  110. payload = {'method': 'post', 'key': self.api_key, 'json': '1'}
  111. # readys file for upload
  112. data = {'file': ('captcha.png', captcha, 'image/png')}
  113. # sends request to 2captcha api to solve captcha
  114. r = requests.post('http://2captcha.com/in.php', data=payload, files=data)
  115. # creates payload
  116. payload = {'key': self.api_key, 'action': 'get', 'id': r.json()['request'], 'json': '1'}
  117. # loops until it gets response
  118. while True:
  119. # sends request to api
  120. capacha_response = requests.get('http://2captcha.com/res.php', params=payload)
  121. # checks if the captcha is ready
  122. if capacha_response.json()['request'] != 'CAPCHA_NOT_READY':
  123. # decodes and returns response
  124. return html.unescape(capacha_response.json()['request'])
  125.  
  126. if __name__ == '__main__':
  127. # gets filename from user
  128. filename = input('Please enter the name of your combo list: ')
  129. # reads file
  130. try:
  131. # tries to open file
  132. with open(filename, 'r') as f:
  133. combos = [x.split(':') for x in f.read().split('\n')]
  134. except IOError:
  135. # exits
  136. sys.exit('There was a problem reading the combo file.')
  137. # notifies user the file was read
  138. print('Successfully read combo list.')
  139. # gets group name from user
  140. group = input('Please enter the name of the group to join: ')
  141. # gets avatars
  142. avatars = ['avatars\\' + x for x in os.listdir("avatars")]
  143. print('Loaded avatars.')
  144. print('Bot has started.')
  145. # iterates through list and creates accounts
  146. for username, password, email in combos:
  147. # instantiates bot
  148. bot = SteamBot(api_key='')
  149. # signs up on steam
  150. bot.signup(username=username, password=password, email=email)
  151. # uploads random avatar
  152. bot.upload_avatar(filename=random.choice(avatars))
  153. # makes profile private
  154. bot.make_private()
  155. # joins group
  156. bot.join_group(name=group)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement