Advertisement
otakana

deob for F5 JS

Aug 24th, 2020 (edited)
2,245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.36 KB | None | 0 0
  1. """
  2. relevant strings
  3. "Bad key length (should be 16) "
  4. "Bad block length (should be 8) "
  5. "Decryption failure"
  6. "Called Uint2Str with negative int "
  7. "Cannot convert string of more than 4 bytes"
  8. "ERROR: securemsg.seal failed - ctx is undefined. securemsg must unseal something before sealing."
  9. "bad scope_hex.length "
  10. "Message too short for headers: "
  11. "scope doesn't match: "
  12. "message too short for payload: "
  13. "message too short for signature: "
  14. "Message failed integrity checks during unseal"
  15. "clntcap_success"
  16. "clntcap_frame"
  17. "TSURLCK_test=test_cookie_support"
  18. "TSURLCK_test"
  19. """
  20. import os
  21. import sys
  22. import re
  23. import binascii
  24. re1ex="Z\((?P<varname>\w+)(?P<data>(,\s*(\d*)\s*)+)\)"
  25. re2ex="S\((?P<val>-?\d+),\s*(?P<varname>\w+)\)"
  26. re3ex="S\((?P<val>0x[0-9A-Fa-f]+),\s*(?P<varname>\w+)\)"
  27. re4ex="parseInt\((?P<val>\d+)((\s\+\s\[\])*),\s(?P<base>\d*)\)"
  28. re5ex="z\((?P<varname>\d+)\)\s\?\s(?P<data>[\d\s:]+)"
  29. def b36_encode(i):
  30.     if i < 0: return "-" + b36_encode(-i)
  31.     if i < 36: return "0123456789abcdefghijklmnopqrstuvwxyz"[i]
  32.     return b36_encode(i // 36) + b36_encode(i % 36)    
  33.  
  34. def is_int(Val):
  35.     try:
  36.         int(Val)
  37.         return True
  38.     except:
  39.         return False
  40.  
  41. def decode1(varname=None,data=None,pre=None,default=None):
  42.     rawline=data.replace("\n","").replace(" ","")
  43.     if not is_int(varname):
  44.         varassign="{} = (\d+)".format(varname)
  45.         key=int(find_last(varassign,pre))
  46.     else:
  47.         key=int(varname)
  48.     vals=[int(v) for v in rawline.split(",")[1:]]
  49.     res=bytearray([((v-key)&0xff) for v in vals])
  50.     try:
  51.         return "\"{}\"".format(res.decode('utf-8'))
  52.     except:
  53.         return default
  54.  
  55. def decode2(varname=None,val=None,pre=None,default=None):
  56.     if not is_int(varname):
  57.         varassign="{} = (\d+)".format(varname)
  58.         key=int(find_last(varassign,pre))
  59.     else:
  60.         key=int(varname)
  61.     return "\"{}\"".format(b36_encode(int(val)+key))
  62.  
  63. def decode3(varname=None,val=None,pre=None,default=None):
  64.     val=int(val.split("0x")[-1],16)
  65.     return decode2(varname,val,pre,default)
  66.  
  67. def decode4(val=None,base=None,pre=None,default=None):
  68.     return "{}".format(int(val,int(base)))
  69.  
  70.  
  71. def decode5(varname=None,data=None,pre=None,default=None):
  72.     data=data.replace("\n","").replace(" ","")
  73.     vals=data.split(":")
  74.     if (567>int(varname)):
  75.         return vals[0]
  76.     return vals[1]
  77.    
  78. fixups=[
  79.     (re1ex,decode1),
  80.     (re2ex,decode2),
  81.     (re3ex,decode3),
  82.     (re4ex,decode4),    
  83.     (re5ex,decode5),    
  84. ]
  85.        
  86. def find_last(regex,data):
  87.     try:
  88.         res=re.findall(regex,data)
  89.         if type(res)==type([]):
  90.             res=res[-1]
  91.         return res        
  92.     except Exception as e:
  93.         print("find_last {} - {} {}".format(e,regex,data))
  94.         return None
  95.  
  96. with open(sys.argv[1],"r") as infile:
  97.     data=infile.read()
  98.  
  99. for r in fixups:
  100.     while True:
  101.         try:
  102.             res=re.search(r[0],data ,re.MULTILINE)
  103.             if not res:
  104.                 break
  105.             pre=data[:res.start()]
  106.             post=data[res.end():]
  107.             data=pre+"{}".format(r[1](**res.groupdict(),pre=pre) )+post
  108.         except Exception as e:
  109.             print("Failed {}\nwith {}".format(e,res.groupdict()))
  110.             print("line {}".format(res.group(0)))
  111.             print("pre {}".format(pre[-60:]))
  112.             sys.exit(-1)
  113. print(data)
  114.  
  115.    
  116.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement