From f327077b4ba7210b5533103d7aa9874b51e71be0 Mon Sep 17 00:00:00 2001 From: damies13 Date: Fri, 7 Apr 2023 16:17:55 +1000 Subject: [PATCH] First attempt Issue #5 --- src/modules/h2r_base64.py | 73 +++++++++++++++++++++++++++++++++++++++ src/modules/h2r_http.py | 4 +-- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/modules/h2r_base64.py b/src/modules/h2r_base64.py index 850c266..9e6a01a 100644 --- a/src/modules/h2r_base64.py +++ b/src/modules/h2r_base64.py @@ -1,4 +1,5 @@ # base64 Module - encoding and decoding base64 encoded values +import base64 class h2r_base64(): """docstring for .""" @@ -6,3 +7,75 @@ class h2r_base64(): def __init__(self, parent): # super(, self).__init__() self.parent = parent + + # + # Register Encoders + # + + b64 = "03:self.h2r_base64.base64_encode" + if b64 not in self.parent.encoders: + self.parent.encoders[b64] = {} + self.parent.encoders[b64]["robottranscode"] = "self.h2r_base64.base64_decode" + + # + # Register Decoders + # + + b64 = "03:self.h2r_base64.base64_decode" + if b64 not in self.parent.encoders: + self.parent.decoders[b64] = {} + self.parent.decoders[b64]["robottranscode"] = "self.h2r_base64.base64_encode" + + # + # Register Paersers + # + + # + # Register processors + # + + + # + # Encoders + # + + def base64_encode(self, s): + try: + s_bytes = s.encode('utf_8') + base64_bytes = base64.b64encode(s_bytes) + base64_s = base64_bytes.decode('utf_8') + return base64_s + except Exception: + return s + + # + # Decoders + # + + def base64_decode(self, s): + try: + # s_bytes = s.encode('utf_8') + s_bytes = s.encode() + dec_bytes = base64.b64decode(s_bytes) + # dec_s = dec_bytes.decode('utf_8') + dec_s = dec_bytes.decode() + return dec_s + except Exception: + return s + + + # + # Paersers + # + + + + # + # processors + # + + + + + +# diff --git a/src/modules/h2r_http.py b/src/modules/h2r_http.py index 7d6f267..9569a6c 100644 --- a/src/modules/h2r_http.py +++ b/src/modules/h2r_http.py @@ -83,7 +83,7 @@ def response_headers(self): estep = self.parent.find_estep(resp, ekwname) # check headers - self.parent.debugmsg(6, "is searchval in headers:", searchval) + self.parent.debugmsg(7, "is searchval in headers:", searchval) for h in e["response"]["headers"]: if h["value"] == searchval and h["name"] in searchkeys: hkey = h["name"] @@ -209,7 +209,7 @@ def response_cookies(self): # check Cookies - self.parent.debugmsg(6, "is searchval in cookies:", searchval) + self.parent.debugmsg(7, "is searchval in cookies:", searchval) for c in e["response"]["cookies"]: if c["value"] == searchval and c["name"] in searchkeys: ckey = c["name"]