Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Asset_Discovery
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yogesh.m
Asset_Discovery
Commits
e9629dd6
Commit
e9629dd6
authored
Aug 21, 2023
by
Dipti mishra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Altered codesys protocol
parent
59f2239d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
47 deletions
+61
-47
.gitignore
.gitignore
+4
-0
protocol_discover_helpers/codesys_discover.py
protocol_discover_helpers/codesys_discover.py
+3
-0
protocol_enumerators/codesys.py
protocol_enumerators/codesys.py
+54
-47
No files found.
.gitignore
0 → 100644
View file @
e9629dd6
*.pyc
*.cypython-311.pyc
assets.json
migrations
\ No newline at end of file
protocol_discover_helpers/codesys_discover.py
0 → 100644
View file @
e9629dd6
def
protocol_identify
(
hex_pkt
):
if
(
b
'bbbb'
in
hex_pkt
and
hex_pkt
[
108
:
112
]
==
b
'bbbb'
):
return
":codesys"
\ No newline at end of file
protocol_enumerators/codesys.py
View file @
e9629dd6
import
binascii
from
scapy.all
import
*
import
socket
import
binascii
def
action
(
host
,
port
):
# CoDeSyS little endian query
lile_query
=
binascii
.
unhexlify
(
"bbbb0100000001"
)
# CoDeSyS big endian query
bige_query
=
binascii
.
unhexlify
(
"bbbb0100000101"
)
# Create a socket
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
try
:
# Connect to the remote host
sock
.
connect
((
host
,
port
))
# Send the little endian query
sock
.
send
(
lile_query
)
# Receive the response
response
=
sock
.
recv
(
1024
)
# If there was no response, try the big endian query
if
not
response
:
sock
.
send
(
bige_query
)
response
=
sock
.
recv
(
1024
)
# Check if the response starts with 0xbb
if
response
and
response
[
0
]
==
0xbb
:
# Extract the null-terminated strings (OS Name, OS Type, Product Type)
os_name_end
=
response
.
find
(
b
'
\x00
'
,
64
)
os_name
=
response
[
64
:
os_name_end
]
.
decode
()
os_type_end
=
response
.
find
(
b
'
\x00
'
,
96
)
os_type
=
response
[
96
:
os_type_end
]
.
decode
()
product_type_end
=
response
.
find
(
b
'
\x00
'
,
128
)
product_type
=
response
[
128
:
product_type_end
]
.
decode
()
# Close the socket
sock
.
close
()
output
=
{
"OS Name"
:
os_name
,
"Product Type"
:
product_type
,
"Device IP"
:
host
,
"Port"
:
port
}
return
output
except
Exception
as
e
:
print
(
f
"Error: {e}"
)
return
None
def
action
(
host
,
port
):
output
=
{}
cotp
=
binascii
.
unhexlify
(
'0300001611e00000001400c1020100c2020102c0010a'
)
alt_COTP
=
binascii
.
unhexlify
(
"0300001611e00000000500c1020100c2020200c0010a"
)
ROSCTR_Setup
=
binascii
.
unhexlify
(
"0300001902f08032010000000000080000f0000001000101e0"
)
Read_SZL
=
binascii
.
unhexlify
(
"0300002102f080320700000000000800080001120411440100ff09000400110001"
)
first_SZL_Request
=
binascii
.
unhexlify
(
"0300002102f080320700000000000800080001120411440100ff09000400110001"
)
second_SZL_Request
=
binascii
.
unhexlify
(
"0300002102f080320700000000000800080001120411440100ff090004001c0001"
)
response
=
None
pkt
=
Ether
(
cotp
)
MESSAGE
=
pkt
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
try
:
s
.
settimeout
(
3
)
s
.
connect
((
host
,
port
))
except
:
return
False
response
=
send_receive
(
s
,
cotp
)
if
(
response
):
if
(
hex
(
response
[
5
])
!=
"0xd0"
):
s
.
close
()
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
connect
((
host
,
port
))
response
=
send_receive
(
s
,
alt_COTP
)
if
(
response
):
if
(
hex
(
response
[
5
])
!=
"0xd0"
):
return
False
response
=
send_receive
(
s
,
ROSCTR_Setup
)
if
(
response
):
if
(
hex
(
response
[
7
])
!=
"0x32"
):
return
False
response
=
send_receive
(
s
,
Read_SZL
)
if
(
response
):
if
(
hex
(
response
[
7
])
!=
"0x32"
):
return
False
response
=
send_receive
(
s
,
first_SZL_Request
)
try
:
output
=
first_parse_response
(
response
,
output
)
except
:
return
False
response
=
send_receive
(
s
,
second_SZL_Request
)
output
=
second_parse_response
(
response
,
output
)
output
[
"DeviceIP"
]
=
host
output
[
"Port"
]
=
port
return
output
\ No newline at end of file
def
get_info
(
ip
,
port
):
return
(
action
(
ip
,
port
))
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment