Merge branch 'wifi' into 'main'

Add bash file with functions to enable and disable monitor mode using either...

See merge request dmi-pet/bsc-msc/2024-bsc-sebastian-lenzlinger!5
This commit is contained in:
Sebastian Lenzlinger 2024-05-02 17:15:51 +00:00
commit 822b49ed8b
6 changed files with 115 additions and 49 deletions

View File

@ -4,4 +4,7 @@
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="py.test" />
</component>
</module>

81
.idea/workspace.xml generated
View File

@ -4,28 +4,13 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="7a3ac8e1-7fbf-4aa7-9cf9-a51d7ade8503" name="Changes" comment="Start tracking development config files.">
<change afterPath="$PROJECT_DIR$/.idea/webResources.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/kydcap/subcommands/__init__.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/tests/fixtures/__init__.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/tests/fixtures/shared_fixtures.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/tests/models/test_capture_metadata_model.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/tests/models/test_device_metadata_model.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/tests/subcommands/test_initialize_device_root_dir.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/tests/subcommands/test_sniff.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/tests/test_main.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/tests/utils/test_capture_metadata_utils.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/tests/utils/test_device_metadata_utils.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/tests/utils/test_tcpdump_utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<list default="true" id="7a3ac8e1-7fbf-4aa7-9cf9-a51d7ade8503" name="Changes" comment="Setup testing structure">
<change afterPath="$PROJECT_DIR$/code/kydcap/scripts/wifi_ctl.sh" afterDir="false" />
<change afterPath="$PROJECT_DIR$/code/kydcap/utils/wifi_ctrl_utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/2024-bsc-sebastian-lenzlinger.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/2024-bsc-sebastian-lenzlinger.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/archive/metadata_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/archive/metadata_utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code/kydcap/config.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/kydcap/config.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code/kydcap/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/kydcap/__main__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code/kydcap/models/capture_metadata.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/kydcap/models/capture_metadata_model.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code/kydcap/models/device_metadata.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/kydcap/models/device_metadata_model.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code/kydcap/subcommands/initialize_device_root_dir.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/kydcap/subcommands/initialize_device_root_dir.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code/kydcap/subcommands/sniff.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/kydcap/subcommands/sniff.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/code/kydcap/utils/tcpdump_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/code/kydcap/utils/utils.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -59,27 +44,27 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_ADD_EXTERNAL_FILES": "true",
"ASKED_MARK_IGNORED_FILES_AS_EXCLUDED": "true",
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
"Python.__init__.executor": "Run",
"Python.__main__.executor": "Run",
"Python.main.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "main",
"last_opened_file_path": "/home/slnopriv/projects/2024-bsc-sebastian-lenzlinger/code/kydcap/utils/device_metadata_utils.py",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
&quot;ASKED_MARK_IGNORED_FILES_AS_EXCLUDED&quot;: &quot;true&quot;,
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;Python.__init__.executor&quot;: &quot;Run&quot;,
&quot;Python.__main__.executor&quot;: &quot;Run&quot;,
&quot;Python.main.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/slnopriv/projects/2024-bsc-sebastian-lenzlinger/code/kydcap/utils/device_metadata_utils.py&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/archive" />
@ -165,7 +150,8 @@
<workItem from="1713967495566" duration="6927000" />
<workItem from="1714554228183" duration="34000" />
<workItem from="1714554269789" duration="56478000" />
<workItem from="1714616237168" duration="6135000" />
<workItem from="1714616237168" duration="9071000" />
<workItem from="1714631778143" duration="1000000" />
</task>
<task id="LOCAL-00001" summary="Add code for capture testbed. This is a huge commit. End of day sync...">
<option name="closed" value="true" />
@ -215,7 +201,15 @@
<option name="project" value="LOCAL" />
<updated>1714617266799</updated>
</task>
<option name="localTasksCounter" value="7" />
<task id="LOCAL-00007" summary="Setup testing structure">
<option name="closed" value="true" />
<created>1714622469786</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1714622469786</updated>
</task>
<option name="localTasksCounter" value="8" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -271,7 +265,8 @@
<MESSAGE value="Add test module." />
<MESSAGE value="Update gitignore again." />
<MESSAGE value="Start tracking development config files." />
<option name="LAST_COMMIT_MESSAGE" value="Start tracking development config files." />
<MESSAGE value="Setup testing structure" />
<option name="LAST_COMMIT_MESSAGE" value="Setup testing structure" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/2024_bsc_sebastian_lenzlinger$__init__.coverage" NAME="__init__ Coverage Results" MODIFIED="1714619300966" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/code/kydcap" />

View File

@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Note, this is not my original work. Source: https://linuxtldr.com/changing-interface-mode/
function list_nic_info () {
ip addr show
}
function enable_monm_iw () {
interface=$1
sudo ip link set "$interface" down
sudo iw "$interface" set monitor control
sudo ip link set "$interface" up
}
function disable_monm_iw () {
interface=$1
sudo ip link set "$interface" down
sudo iw "$interface" set type managed
sudo ip link set "$interface" up
}
function enable_monm_iwconfig () {
interface=$1
sudo ifconfig "$interface" down
sudo iwconfig "$interface" mode monitor
sudo ifconfig "$interface" up
}
function disable_monm_iwconfig () {
interface=$1
sudo ifconfig "$interface" down
sudo iwconfig "$interface" mode managed
sudo ifconfig "$interface" up
}
function enable_monm_acng () {
interface=$1
sudo airmon-ng check
sudo airmon-ng check kill
sudo airmon-ng start "$interface"
}
function disable_monm_acng () {
interface="${1}mon"
sudo airmon-ng stop "$interface"
sudo systemctl restart NetworkManager
}
if declare -f "$1" > /dev/null
then
"$@"
else
echo "Unknown function '$1'" >&2
exit 1
fi

View File

@ -69,7 +69,7 @@ def handle_sniff(args):
if not cwd_is_device_root_dir():
handle_metadata()
else:
cmd = ['sudo tcpdump', '-i', args.capture_interface]
cmd = ['sudo', 'tcpdump', '-i', args.capture_interface]
if args.monitor_mode:
cmd.append('-I')
if args.no_name_resolution:
@ -83,8 +83,10 @@ def handle_sniff(args):
cmd.append(str(args.count))
elif args.mins:
pass
print('Executing: ' + ' '.join(cmd))
print('Complete command:' + ' '.join(cmd))
# TODO maybe dump this into file -> put into device metadata
# TODO generate pcap filename
# TODO construct capture metadata file
try:
start_time = datetime.now().strftime('%H:%M:%S')
subprocess.run(cmd)

View File

@ -1,15 +1,16 @@
import shutil
import subprocess
DEPENDENCIES =
def check_installed() -> bool:
def check_installed(tool) -> bool:
"""Check if tcpdump is installed and available on the system path."""
return shutil.which('tcpdump') is not None
return shutil.which(f'{tool}') is not None
def ensure_installed():
def ensure_installed(tool):
"""Ensure that tcpdump is installed, raise an error if not."""
if not check_installed():
if not check_installed(tool):
raise RuntimeError("tcpdump is not installed. Please install it to continue.")

View File

@ -0,0 +1,10 @@
import subprocess
def enable_monitor_mode(interface):
pass
def disable_monitor_mode(interface):
pass
def get_ap_channel(interface):
pass