Skip to content

Commit

Permalink
reverted back to original Updated build script and .spec file for aut…
Browse files Browse the repository at this point in the history
…o packaging to rpm
  • Loading branch information
BradHeff committed Dec 11, 2024
1 parent b3a3503 commit 8ed4eef
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 259 deletions.
2 changes: 2 additions & 0 deletions aptester.spec → arxis-pentester.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Requires: python3, python3-tkinter, python3-pillow-tk, python3-pip
%description
The application helps identify vulnerable open ports on a network, providing insights into potential security risks.

%pre
pip3 install ipaddress asyncio numpy ttkbootstrap pillow logging tkthread

%install
mkdir -p %{buildroot}/usr/local/bin/
Expand Down
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ipaddress
asyncio
numpy
ttkbootstrap
pillow
logging
tkthread
159 changes: 86 additions & 73 deletions usr/lib/arxis-pentest-tool/Functions.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,102 @@
import asyncio
import ipaddress
import socket
import logging
import asyncio
import numpy as np
import socket

logger = logging.getLogger(__name__)
Version = "1.0.1.5"


async def perform_port_scan(ip, port):
"""Check if a TCP connection can be established to the host on the given port."""
try:
reader, writer = await asyncio.open_connection(ip, port)
writer.close()
await writer.wait_closed()
return True
except Exception:
return False
async def scan_host(self, subnet, port_list):
self.logger.info(f"Scanning IP addresses in {subnet}...")
self.logger.info("----------------------------------------------------------")
ip_net = ipaddress.ip_network(subnet)
all_hosts = list(ip_net.hosts())
tasks = [scan_ports(self, str(ip), port_list) for ip in all_hosts]
await asyncio.gather(*tasks)


async def TCP_connect(self, ip, port_number):

async def resolve_hostname(ip):
"""Resolve the hostname for an IP address."""
conn = asyncio.open_connection(ip, port_number)
try:
return socket.gethostbyaddr(ip)[0]
except socket.herror:
return "Unknown"
reader, writer = await asyncio.wait_for(conn, timeout=5)
writer.close()
await writer.wait_closed()
return port_number, "Listening"
except (asyncio.TimeoutError, ConnectionRefusedError):
return port_number, ""
except OSError:
return port_number, ""


async def scan_host(window, host, port_list, update_progress):
"""Scan a single host for open ports."""
window.logger.info(f"Scanning host: {host}")
async def get_hostname(ip):
try:
# Convert port list to a numpy array for efficient handling
port_list = np.array(port_list)
open_ports = await perform_port_scan(host, port_list)
hostname = await resolve_hostname(host)

# Ensure Treeview update is called in the main thread
window.loop.call_soon_threadsafe(
lambda: window.update_treeview(
host, open_ports.tolist(), hostname
) # Convert numpy array back to list
hostname, _, _ = await asyncio.wait_for(
asyncio.to_thread(socket.gethostbyaddr, ip), timeout=3
)
return hostname.split()[0]
except (socket.herror, asyncio.TimeoutError):
return "Unknown"

# Await the update_progress coroutine to ensure it runs properly
await update_progress() # Update the progress bar
except Exception as e:
window.logger.error(f"Error scanning {host}: {e}")
finally:
window.logger.info(f"Finished scanning host: {host}")


async def scan_subnet(window, subnet, port_list, update_progress):
"""Scan all hosts in the given subnet."""
network = ipaddress.IPv4Network(subnet, strict=False)
total_hosts = len(list(network.hosts()))
scanned_hosts = 0

# Convert port list to numpy array for better performance
port_list = np.array(port_list)

async def update_progress():
"""Update the progress bar and meter."""
nonlocal scanned_hosts
scanned_hosts += 1
progress = (scanned_hosts / total_hosts) * 100
window.loop.call_soon_threadsafe(
lambda: [
window.progress.config(value=progress),
window.status.config(text=f"Scanning progress: {progress:.2f}%"),
window.meter.configure(amountused=scanned_hosts),
]
)
async def scan_ports(self, host_ip, port_list):
hostname = await get_hostname(host_ip)
max_concurrent_connections = self.meter.amountusedvar.get()

tasks = [
scan_host(window, str(ip), port_list, update_progress) for ip in network.hosts()
]
try:
await asyncio.gather(*tasks)
except asyncio.CancelledError:
window.logger.info("Scan was cancelled.")
finally:
window.loop.call_soon_threadsafe(
lambda: window.status.config(text="Scan complete!")
self.logger.info(
"Running {} concurrent connections on host {}".format(
max_concurrent_connections, host_ip
)


def Version():
return "1.0.15"
)
semaphore = asyncio.Semaphore(max_concurrent_connections)

async def limited_tcp_connect(ip, port):
async with semaphore:
return await TCP_connect(self, ip, port)

port_array = np.array(port_list, dtype=int)
# tasks = [TCP_connect(self, host_ip, port) for port in port_array]
tasks = [limited_tcp_connect(host_ip, port) for port in port_array]
results = await asyncio.gather(*tasks)
res = np.array([], dtype=int)
for port, status in results:
if status == "Listening":
res = np.append(res, port)
self.results[host_ip] = {
"ports": res.tolist(),
"hostname": hostname,
}
existing_item = None
for item in self.tree.get_children():
if self.tree.item(item, "values")[0] == host_ip:
existing_item = item
break

if existing_item:
self.tree.item(
existing_item,
values=(
host_ip,
np.array2string(np.array(res.tolist()), separator=", ")
.replace("[", "")
.replace("]", "")
.replace(" ", "")
.strip(),
hostname,
),
)
else:
self.tree.insert(
"",
"end",
values=(
host_ip,
np.array2string(np.array(res.tolist()), separator=", ")
.replace("[", "")
.replace("]", "")
.replace(" ", "")
.strip(),
hostname,
),
)
print(f"{host_ip}:{port} - {status}")
61 changes: 17 additions & 44 deletions usr/lib/arxis-pentest-tool/Gui.py

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
55 changes: 17 additions & 38 deletions usr/lib/arxis-pentest-tool/build-rpm
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,21 @@
# Stop script on errors
set -e

# Define source and build directories
SOURCE_DIR=$(pwd)
BUILD_DIR=~/rpmbuild/BUILD/APT
SPEC_DIR=~/rpmbuild/SPECS
ZIP_DIR=~/rpmbuild/SOURCES
BASH_SCRIPT="../../local/bin"
FUNCTIONS="$SOURCE_DIR/Functions.py"

# Ensure build directory exists
mkdir -p $BUILD_DIR

# Step 1: Update DEBUG variable in the Bash script
echo "Setting DEBUG to false in the Bash script..."
sed -i 's/^DEBUG=true/DEBUG=false/' $BASH_SCRIPT/arxis-pentester

# Automatically increment the version number in the .spec file
echo "Incrementing version number in the .spec file..."
sed -i -E 's/^(Version:[[:space:]]*)([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/echo "\1\2.\3.\4.$((\5+1))"/e' $SPEC_DIR/aptester.spec
sed -i -E 's/^(Version[[:space:]]=[[:space:]]*)([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/echo "\1\2.\3.\4.$((\5+1))"/e' $FUNCTIONS

# Extract the version number from the .spec file
VERSION=$(grep -E '^Version:[[:space:]]*' $SPEC_DIR/aptester.spec | awk '{print $2}')

#!/bin/bash
# Stop script on errors
set -e
APP_NAME="arxis-pentester"

# Define source and build directories
EXEC_DIR=$(pwd)


# Calculate the parent directory two levels up
PARENT_X3_DIR=$(dirname "$(dirname "$(dirname "$EXEC_DIR")")")


# Define source and build directories
SOURCE_DIR=$EXEC_DIR
BUILD_DIR=~/rpmbuild/BUILD/APT
SPEC_DIR=~/rpmbuild/SPECS
ZIP_DIR=~/rpmbuild/SOURCES
BUILD_DIR=$HOME/rpmbuild/BUILD/APT
SPEC_DIR=$HOME/rpmbuild/SPECS
ZIP_DIR=$HOME/rpmbuild/SOURCES
BASH_SCRIPT="../../local/bin"
USRSOURCE="$PARENT_X3_DIR"
FUNCTIONS="$SOURCE_DIR/Functions.py"
Expand All @@ -50,29 +26,33 @@ mkdir -p $BUILD_DIR

# Step 1: Update DEBUG variable in the Bash script
echo "Setting DEBUG to false in the Bash script..."
sed -i 's/^DEBUG=true/DEBUG=false/' $BASH_SCRIPT/arxis-pentester
sed -i 's/^DEBUG=true/DEBUG=false/' $BASH_SCRIPT/$APP_NAME

# Automatically increment the version number in the .spec file
echo "Incrementing version number in the .spec file..."
sed -i -E 's/^(Version:[[:space:]]*)([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/echo "\1\2.\3.\4.$((\5+1))"/e' $SPEC_DIR/aptester.spec
sed -i -E 's/^(Version:[[:space:]]*)([0-9]+)\.([0-9]+)/echo "\1\2.$((\3+1))"/e' "$SPEC_DIR/$APP_NAME.spec"

# Increment version number in Functions.py
echo "Incrementing version number in Functions.py..."
sed -i -E 's/^(Version[[:space:]]*=[[:space:]]*")([0-9]+\.[0-9]+)\.([0-9]+)"/echo "\1\2.$((\3+1))\""/e' "$FUNCTIONS"

# Extract the version number from the .spec file
VERSION=$(grep -E '^Version:[[:space:]]*' $SPEC_DIR/aptester.spec | awk '{print $2}')
VERSION=$(grep -E '^Version:[[:space:]]*' $SPEC_DIR/$APP_NAME.spec | awk '{print $2}')

# Step 2: Compress the PROJECT-ROOT/usr directory
echo "Compressing the $USRSOURCE/usr directory..."
if [ -d "$USRSOURCE/usr" ]; then
tar -czf arxis-pentester-$VERSION.tar.gz -C "$USRSOURCE" usr
tar -czf $APP_NAME-$VERSION.tar.gz -C "$USRSOURCE" usr
else
echo "Error: Directory $USRSOURCE/usr does not exist."
exit 1
fi

# Step 3: Copy the .tar.gz to ZIP_DIR
echo "Copying the .tar.gz to ZIP_DIR..."
cp arxis-pentester-$VERSION.tar.gz $ZIP_DIR/
cp $APP_NAME-$VERSION.tar.gz $ZIP_DIR/

rm arxis-pentester-$VERSION.tar.gz
rm $APP_NAME-$VERSION.tar.gz

# Step 2: Compile Python modules using Cython (optional if needed)
# echo "Compiling Python modules..."
Expand All @@ -99,12 +79,11 @@ echo "Copying files to RPM build directory..."
cp -a ../../local/bin/* $BUILD_DIR/ || echo "No local binaries found to copy."
cp -a ../../share/applications/* $BUILD_DIR/ || echo "No .desktop files found to copy."
cp -a ../../share/pixmaps/* $BUILD_DIR/ || echo "No pixmap icons found to copy."
cp -a ../../lib/arxis-pentester/* $BUILD_DIR/ || echo "No python files found to copy."
cp -a *.py $BUILD_DIR/
cp -a *.py $BUILD_DIR/ || echo "No python files found to copy."
rm -f $BUILD_DIR/compile.py # Remove compile script from package

# Step 5: Build the RPM package
echo "Building RPM package..."
rpmbuild -ba ~/rpmbuild/SPECS/aptester.spec
rpmbuild -ba $HOME/rpmbuild/SPECS/$APP_NAME.spec

echo "Build completed successfully!"
Loading

0 comments on commit 8ed4eef

Please sign in to comment.