Advertisement
Guest User

Untitled

a guest
Jun 20th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import argparse
  2. """
  3. Shiotob DGA
  4.  
  5. Generates domains for the Shiotob malware
  6.  
  7. - top level domains alternate between '.net' and '.com'
  8. - domains are between 14 and 19 characters long
  9. - domains consist of all letters and digits 123945
  10.  
  11. author: baderj@gmx.net
  12. """
  13.  
  14. qwerty = 'qwertyuiopasdfghjklzxcvbnm123945678'
  15.  
  16. def sum_of_characters(domain):
  17. return sum([ord(d) for d in domain[:-3]])
  18.  
  19. def get_next_domain(domain):
  20. sof = sum_of_characters(domain)
  21. ascii_codes = [ord(d) for d in domain] + 100*[0]
  22. old_hostname_length = len(domain) - 4
  23. for i in range(0, 66):
  24. for j in range(0, 66):
  25. edi = j + i
  26. if edi < 65:
  27. p = (old_hostname_length * ascii_codes[j])
  28. cl = p ^ ascii_codes[edi] ^ sof
  29. ascii_codes[edi] = cl & 0xFF
  30.  
  31. """
  32. calculate the new hostname length
  33. max: 255/16 = 15
  34. min: 10
  35. """
  36. cx = ((ascii_codes[2]*old_hostname_length) ^ ascii_codes[0]) & 0xFF
  37. hostname_length = int(cx/16) # at most 15
  38. if hostname_length < 10:
  39. hostname_length = old_hostname_length
  40.  
  41. """
  42. generate hostname
  43. """
  44. for i in range(hostname_length):
  45. index = int(ascii_codes[i]/8) # max 31 --> last 3 chars of qwerty unreachable
  46. bl = ord(qwerty[index])
  47. ascii_codes[i] = bl
  48.  
  49. hostname = ''.join([chr(a) for a in ascii_codes[:hostname_length]])
  50.  
  51. """
  52. append .net or .com (alternating)
  53. """
  54. tld = '.com' if domain.endswith('.net') else '.net'
  55. domain = hostname + tld
  56.  
  57. return domain
  58.  
  59. if __name__=="__main__":
  60. parser = argparse.ArgumentParser()
  61. parser.add_argument('nr_of_domains', type=int)
  62. parser.add_argument('seed')
  63. args = parser.parse_args()
  64. domain = args.seed
  65. for i in range(args.nr_of_domains):
  66. print(domain)
  67. domain = get_next_domain(domain)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement