Commit 034b2b56 authored by yogesh.m's avatar yogesh.m

update

parent 4f11b785
This diff is collapsed.
configuration: configuration:
threads: 20 #number of threads to scan at once threads: 20 #number of threads to scan at once
transfer frequency: 1 #how frequent the scan needs to be transfer frequency: 1 #how frequent the scan needs to be
unifytwin_server_ip_address: https://webhook.site/422d91cf-4c18-4728-b7a0-13f14898c4b1 #Data will be sent back here unifytwin_server_ip_address: https://webhook.site/34c9fd4a-8924-41ab-a01f-383ef36db96b #Data will be sent back here
edge_device_location : Dalmia Cement edge_device_location : Dalmia Cement
null_loopback: False null_loopback: False
interfaces: Wi-Fi interfaces: Wi-Fi
......
import binascii import binascii
import json import json
from protocol_discover_helpers import modbus_discover,enip_discover,s7_discover,omron_discover,bacnet_discover
class Packet_Analyzer(): class Packet_Analyzer():
def __init__(self): def __init__(self):
data=None self.data=None
self.protocol_list={502: modbus_discover,44818:enip_discover,102:s7_discover,9600:omron_discover,47808:bacnet_discover}
def identify_protocol(self,hex_pkt): def identify_protocol(self,hex_pkt):
protocols="" protocols=""
if(b'6300' in hex_pkt and hex_pkt[84:88]==b'6300'):
protocols=protocols+"enip:"
if(b'0300' in hex_pkt and hex_pkt[108:112]==b'0300'):
protocols=protocols+"s7comm:"
if (b'810a' in hex_pkt and hex_pkt[84:88] == b'810a'):
protocols = protocols + "bacnet:"
if ((b'8000' in hex_pkt or b'c000' in hex_pkt) and (hex_pkt[84:88] == b'8000' or hex_pkt[84:88] == b'c000')):
print("omron found")
protocols = protocols + "omron:"
if (b'0000' in hex_pkt and hex_pkt[108:112] == b'0000'):
protocols = protocols + "modbus:"
if(hex_pkt[46:48] == b"06"): if(hex_pkt[46:48] == b"06"):
protocols=protocols+"tcp" protocols=protocols+"tcp"
port=self.get_tcp_port(hex_pkt)
if(port in self.protocol_list):
port_protocol = self.protocol_list[port].protocol_identify(hex_pkt)
if (port_protocol):
protocols = protocols + port_protocol
if (hex_pkt[46:48] == b"11"): if (hex_pkt[46:48] == b"11"):
protocols = protocols + "udp" protocols = protocols + "udp"
port = self.get_udp_port(hex_pkt)
if (port in self.protocol_list):
port_protocol = self.protocol_list[port].protocol_identify(hex_pkt)
if(port_protocol):
protocols = protocols + port_protocol
return protocols return protocols
def get_ip(self,hex_pkt): def get_ip(self,hex_pkt):
......
def protocol_identify(hex_pkt):
if (b'810a' in hex_pkt and hex_pkt[84:88] == b'810a'):
return "bacnet:"
\ No newline at end of file
def protocol_identify(hex_pkt):
if (b'6300' in hex_pkt and hex_pkt[84:88] == b'6300'):
return ":enip"
\ No newline at end of file
def protocol_identify(hex_pkt):
if(hex_pkt[108:112] == b'0000'):
return ":modbus"
\ No newline at end of file
def protocol_identify(hex_pkt):
if ((b'8000' in hex_pkt or b'c000' in hex_pkt) and (hex_pkt[84:88] == b'8000' or hex_pkt[84:88] == b'c000')):
print("omron found")
return ":omron"
\ No newline at end of file
def protocol_identify(hex_pkt):
if (b'0300' in hex_pkt and hex_pkt[108:112] == b'0300'):
return ":s7comm"
\ No newline at end of file
...@@ -74,37 +74,43 @@ def comm(host, port, rsid): ...@@ -74,37 +74,43 @@ def comm(host, port, rsid):
def action(host,port,aggressive): def action(host,port,aggressive):
count=0 count=0
for sid in range(1,247): try:
rsid=form_rsid(sid, 0x11, b"") for sid in range(1,247):
result=comm(host, port, rsid) rsid=form_rsid(sid, 0x11, b"")
if(result!=False and len(result)>8): result=comm(host, port, rsid)
output[sid]={'Slave ID data':'Unknown','Device identification':'Unknown'} if(result!=False and len(result)>8):
if(result[7]==17 or result[7]==145): output[sid]={'Slave ID data':'Unknown','Device identification':'Unknown'}
if(result[7]==17): if(result[7]==17 or result[7]==145):
slave_id = extract_slave_id(result) if(result[7]==17):
output[sid]["Slave ID data"] = slave_id if slave_id else "Unknown" slave_id = extract_slave_id(result)
elif(result[7]==145): output[sid]["Slave ID data"] = slave_id if slave_id else "Unknown"
exception_code = result[8] elif(result[7]==145):
exception_string = modbus_exception_codes[exception_code] if exception_code<12 and exception_code>0 else None exception_code = result[8]
if(exception_string==None): exception_string = modbus_exception_codes[exception_code] if exception_code<12 and exception_code>0 else None
exception_string = "Unknown exception, Code="+str(exception_code) if(exception_string==None):
output[sid]["Error"]=exception_string exception_string = "Unknown exception, Code="+str(exception_code)
else: output[sid]["Error"]=exception_string
return False else:
device_table = discover_device_id(host, port, sid) return False
if (device_table!=None and len(device_table) > 0 ): device_table = discover_device_id(host, port, sid)
output[sid]["Device identification"] = re.sub('[\x00-\x1f]',' ',device_table.decode()).replace(" "," ") if (device_table!=None and len(device_table) > 0 ):
count=0 device_table = re.sub('[\x00-\x1f]',' ',device_table.decode(errors='ignore'))
if not aggressive: output[sid]["Device identification"] = device_table.replace(" "," ")
output[sid]["sid"]="sid"+str(sid) count=0
return output[sid] if not aggressive:
elif(result=='terr' and count>2): output[sid]["sid"]="sid"+str(sid)
return False return output[sid]
elif(result==False): elif(result=='terr' and count>2):
return False return False
else: elif(result==False):
count=count+1 return False
return json.dumps(output) else:
count=count+1
return json.dumps(output)
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno, e)
def get_info(ip,port,aggressive=False): def get_info(ip,port,aggressive=False):
......
import openai from protocol_discover_helpers import modbus_discover
# Define OpenAI API key dicc = {"502": modbus_discover}
openai.api_key = "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"
# Set up the model and prompt print(dicc["502"].protocol_identify("7c76356ad4847c5a1c7f6eef08004500016e64580000fa06d5bfa68d1c8ac0a801b201f67448f87b9f607ba3597550181765211b00000000000000fe012b0e0182000003000341424201023333021156322e352e312c323031352d31312d32360000000096000000960233333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333000c09300008000000230000602210208000860200210000018040110000040100100000000000000039"))
model_engine = "text-davinci-003" hex_pkt=b'7c76356ad4847c5a1c7f6eef08004500016e64580000fa06d5bfa68d1c8ac0a801b201f67448f87b9f607ba3597550181765211b00000000000000fe012b0e0182000003000341424201023333021156322e352e312c323031352d31312d32360000000096000000960233333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333000c09300008000000230000602210208000860200210000018040110000040100100000000000000039'
prompt = "give me a random youtube funny comment and keep it simple from 6 to 20 words along with emojis scene:dog chewing ball"
# Generate a response def protocol_identify(hex_pkt):
completion = openai.Completion.create( if(hex_pkt[108:112] == b'0000'):
engine=model_engine, hex_pkt=hex_pkt[108:]
prompt=prompt, tid=int(hex_pkt[0:4].decode(), 16)
max_tokens=1024, pid=int(hex_pkt[4:8].decode(), 16)
n=1, length=int(hex_pkt[8:12].decode(), 16)
stop=None, print(len(hex_pkt[0:])/2)
temperature=0.9,
)
response = completion.choices[0].text
print(response)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment