Skip to content

Commit

Permalink
Test IP spoofing
Browse files Browse the repository at this point in the history
Signed-off-by: Samuli Leivo <[email protected]>
  • Loading branch information
leivos-unikie committed Dec 30, 2024
1 parent eab6735 commit 4859c53
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Robot-Framework/resources/ssh_keywords.resource
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,21 @@ Get wifi IP
END
IF ${status} == False FAIL NetVM hasn't gotten an IP

Get Virtual Network Interface IP
[Documentation] Parse ifconfig output and look for ethint0 IP
${if_name}= Set Variable ethint0
FOR ${i} IN RANGE 20
${output} Execute Command ifconfig
Log ${output}
${ip} Get ip from ifconfig ${output} ${if_name}
IF $ip != '${EMPTY}'
Log ${ip}
RETURN ${ip}
END
Sleep 1
END
FAIL IP address not found.

Check if ssh is ready on device
[Arguments] ${timeout}=30
${is_ready} Set Variable False
Expand Down
2 changes: 1 addition & 1 deletion Robot-Framework/test-suites/bat-tests/netvm.robot
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Wifi passthrought into NetVM
[Setup] Run Keywords
... Connect to ghaf host AND Connect to netvm
Configure wifi ${netvm_ssh} ${TEST_WIFI_SSID} ${TEST_WIFI_PSWD}
Get wifi IP
Get Network Interface IP wifi
Check Network Availability 8.8.8.8 expected_result=True
Turn OFF WiFi ${TEST_WIFI_SSID}
Check Network Availability 8.8.8.8 expected_result=False
Expand Down
36 changes: 36 additions & 0 deletions Robot-Framework/test-suites/security-tests/__init__.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-FileCopyrightText: 2022-2024 Technology Innovation Institute (TII)
# SPDX-License-Identifier: Apache-2.0

*** Settings ***
Documentation Security tests
Resource ../../resources/ssh_keywords.resource
Resource ../../resources/common_keywords.resource
Suite Setup Common Setup
Suite Teardown Common Teardown

*** Variables ***

${connection} ${NONE}

*** Keywords ***

Common Setup
Set Variables ${DEVICE}
Run Keyword If "${DEVICE_IP_ADDRESS}" == "NONE" Get ethernet IP address
${port_22_is_available} Check if ssh is ready on device timeout=60
IF ${port_22_is_available} == False
FAIL Failed because port 22 of device was not available, tests can not be run.
END
${connection} Connect
${out} Execute Command hostname
Log ${out}
Set Suite Variable ${connection} ${connection}
Log versions
Run journalctl recording

Common Teardown
IF ${connection}
Connect
Log journctl
END
Close All Connections
7 changes: 7 additions & 0 deletions Robot-Framework/test-suites/security-tests/nc_client
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ip_server=192.168.100.4

for i in {1..35}
do
echo " ---- packet $i " | nc -w 1 ${ip_server} 5201
sleep 1.5
done
11 changes: 11 additions & 0 deletions Robot-Framework/test-suites/security-tests/nc_server
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sudo iptables -F

echo "" > /tmp/server_received.txt

for i in {1..30}
do
echo "" >> /tmp/server_received.txt
echo "iteration $i - $(date)" >> /tmp/server_received.txt
timeout 1.7 nc -l 5201 >> /tmp/server_received.txt 2>&1
sleep 0.5
done
19 changes: 19 additions & 0 deletions Robot-Framework/test-suites/security-tests/nc_stealer
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ip_server=192.168.100.4
# ip_stealer=192.168.100.6

sudo iptables -F

echo "" > /tmp/stolen.txt

for i in {1..30}
do
echo "" >> /tmp/stolen.txt
echo "iteration $i - $(date)" >> /tmp/stolen.txt
sudo ifconfig ethint0 ${ip_server} netmask 255.255.255.0 up
sleep 0.3
sudo ifconfig ethint0 ${ip_server} netmask 255.255.255.0 up
sleep 0.3
timeout 1 nc -l 5201 >> /tmp/stolen.txt 2>&1
sudo ifconfig ethint0 ${ip_stealer} netmask 255.255.255.0 up
sleep 0.3
done
81 changes: 81 additions & 0 deletions Robot-Framework/test-suites/security-tests/security_tests.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# SPDX-FileCopyrightText: 2022-2024 Technology Innovation Institute (TII)
# SPDX-License-Identifier: Apache-2.0

*** Settings ***
Force Tags security
Resource ../../resources/ssh_keywords.resource
Resource ../../config/variables.robot
Resource ../../resources/common_keywords.resource
Suite Teardown Close All Connections


*** Variables ***
${connection}


*** Test Cases ***

Test IP spoofing
[Documentation] Test if it's possible to steal packets via ip spoofing
[Tags] SP-T128 lenovo-x1
# Prepare netcat server script
Connect to netvm
Check if ssh is ready on vm ${GALA_VM}
Connect to VM ${GALA_VM}
${ip_gala} Get Virtual Network Interface IP
Put File security-tests/nc_server /tmp
Execute Command chmod 777 /tmp/nc_server

# Prepare netcat client script
Connect to netvm
Check if ssh is ready on vm ${COMMS_VM}
Connect to VM ${COMMS_VM}
Put File security-tests/nc_client /tmp
Execute Command echo 'ip_server=${ip_gala}' > /tmp/tmp_file
Execute Command cat /tmp/nc_client >> /tmp/tmp_file
Execute Command cp /tmp/tmp_file /tmp/nc_client
Execute Command chmod 777 /tmp/nc_client

# Prepare netcat stealer script
Connect to netvm
Check if ssh is ready on vm ${CHROME_VM}
Connect to VM ${CHROME_VM}
${ip_chrome} Get Virtual Network Interface IP
Put File security-tests/nc_stealer /tmp
Execute Command echo 'ip_server=${ip_gala}\nip_stealer=${ip_chrome}' > /tmp/tmp_file
Execute Command cat /tmp/nc_stealer >> /tmp/tmp_file
Execute Command cp /tmp/tmp_file /tmp/nc_stealer
Execute Command chmod 777 /tmp/nc_stealer

# Launch the test scripts
Connect to VM ${GALA_VM}
Run Keyword And Ignore Error Execute Command -b /tmp/nc_server sudo=True sudo_password=${PASSWORD} timeout=3
Connect to VM ${COMMS_VM}
Run Keyword And Ignore Error Execute Command -b /tmp/nc_client sudo=True sudo_password=${PASSWORD} timeout=3
Connect to VM ${CHROME_VM}
Run Keyword And Ignore Error Execute Command -b /tmp/nc_stealer sudo=True sudo_password=${PASSWORD} timeout=3
Log To Console Waiting 40 sec for the test to finish
Sleep 40
Close All Connections

# Check the result files
Connect
Connect to netvm
Check if ssh is ready on vm ${CHROME_VM}
Connect to VM ${CHROME_VM}
${stolen} Execute Command cat /tmp/stolen.txt | grep packet
Log ${stolen}
${stealer_log} Execute Command cat /tmp/stolen.txt
Log ${stealer_log}
Connect to VM ${GALA_VM}
${server} Execute Command cat /tmp/server_received.txt | grep packet
Log ${server}
${server_log} Execute Command cat /tmp/server_received.txt
Log ${server_log}
IF $stolen != '${EMPTY}'
FAIL Stealer VM managed to receive packets via ip spoofing
END
IF $server == '${EMPTY}' and $stolen == '${EMPTY}'
FAIL No packets received by server or stealer VM
END

0 comments on commit 4859c53

Please sign in to comment.