mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
@ -1,65 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
usage() {
|
||||
echo "Usage: backup.sh [-honu] [-h] [-u user] [-n host name or ip] [-o output]"
|
||||
}
|
||||
|
||||
while getopts "ho:n:u:" arg; do
|
||||
case $arg in
|
||||
h)
|
||||
usage
|
||||
exit
|
||||
;;
|
||||
n)
|
||||
UNIT_HOSTNAME=$OPTARG
|
||||
;;
|
||||
o)
|
||||
OUTPUT=$OPTARG
|
||||
;;
|
||||
u)
|
||||
UNIT_USERNAME=$OPTARG
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
|
||||
# name of the ethernet gadget interface on the host
|
||||
UNIT_HOSTNAME=${UNIT_HOSTNAME:-10.0.0.2}
|
||||
# output backup tgz file
|
||||
OUTPUT=${OUTPUT:-${UNIT_HOSTNAME}-backup-$(date +%s).tgz}
|
||||
# username to use for ssh
|
||||
UNIT_USERNAME=${UNIT_USERNAME:-pi}
|
||||
# what to backup
|
||||
FILES_TO_BACKUP="/root/brain.nn \
|
||||
/root/brain.json \
|
||||
/root/.api-report.json \
|
||||
/root/.ssh \
|
||||
/root/.bashrc \
|
||||
/root/.profile \
|
||||
/root/handshakes \
|
||||
/root/peers \
|
||||
/etc/pwnagotchi/ \
|
||||
/etc/ssh/ \
|
||||
/var/log/pwnagotchi.log \
|
||||
/var/log/pwnagotchi*.gz \
|
||||
/home/pi/.ssh \
|
||||
/home/pi/.bashrc \
|
||||
/home/pi/.profile \
|
||||
/root/.api-report.json \
|
||||
/root/.auto-update \
|
||||
/root/.bt-tether* \
|
||||
/root/.net_pos_saved \
|
||||
/root/.ohc_uploads \
|
||||
/root/.wigle_uploads \
|
||||
/root/.wpa_sec_uploads"
|
||||
|
||||
ping -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || {
|
||||
echo "@ unit ${UNIT_HOSTNAME} can't be reached, make sure it's connected and a static IP assigned to the USB interface."
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "@ backing up $UNIT_HOSTNAME to $OUTPUT ..."
|
||||
# shellcheck disable=SC2029
|
||||
ssh "${UNIT_USERNAME}@${UNIT_HOSTNAME}" "sudo find ${FILES_TO_BACKUP} -type f -print0 | xargs -0 sudo tar cv" | gzip -9 > "$OUTPUT"
|
@ -1,73 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
DEPENDENCIES=( 'xgettext' 'msgfmt' 'msgmerge' )
|
||||
COMMANDS=( 'add' 'update' 'delete' 'compile' )
|
||||
|
||||
REPO_DIR="$(dirname "$(dirname "$(realpath "$0")")")"
|
||||
LOCALE_DIR="${REPO_DIR}/pwnagotchi/locale"
|
||||
VOICE_FILE="${REPO_DIR}/pwnagotchi/voice.py"
|
||||
|
||||
function usage() {
|
||||
cat <<EOF
|
||||
|
||||
usage: $0 <command> [options]
|
||||
|
||||
Commands:
|
||||
add <language>
|
||||
delete <language>
|
||||
compile <language>
|
||||
update <language>
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
for REQ in "${DEPENDENCIES[@]}"; do
|
||||
if ! type "$REQ" >/dev/null 2>&1; then
|
||||
echo "Dependency check failed for ${REQ}"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [[ ! "${COMMANDS[*]}" =~ $1 ]]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
|
||||
function add_lang() {
|
||||
mkdir -p "$LOCALE_DIR/$1/LC_MESSAGES"
|
||||
cp -n "$LOCALE_DIR/voice.pot" "$LOCALE_DIR/$1/LC_MESSAGES/voice.po"
|
||||
}
|
||||
|
||||
function del_lang() {
|
||||
# set -eu is present; so not dangerous
|
||||
# shellcheck disable=SC2115
|
||||
rm -rf "$LOCALE_DIR/$1"
|
||||
}
|
||||
|
||||
function comp_lang() {
|
||||
msgfmt -o "$LOCALE_DIR/$1/LC_MESSAGES/voice.mo" "$LOCALE_DIR/$1/LC_MESSAGES/voice.po"
|
||||
}
|
||||
|
||||
function update_lang() {
|
||||
xgettext --no-location -d voice -o "$LOCALE_DIR/voice.pot" "$VOICE_FILE"
|
||||
msgmerge --update "$LOCALE_DIR/$1/LC_MESSAGES/voice.po" "$LOCALE_DIR/voice.pot"
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
add)
|
||||
add_lang "$2"
|
||||
;;
|
||||
delete)
|
||||
del_lang "$2"
|
||||
;;
|
||||
compile)
|
||||
comp_lang "$2"
|
||||
;;
|
||||
update)
|
||||
update_lang "$2"
|
||||
;;
|
||||
esac
|
@ -1,19 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# name of the ethernet gadget interface on the host
|
||||
USB_IFACE=${1:-enp0s20f0u1}
|
||||
USB_IFACE_IP=10.0.0.1
|
||||
USB_IFACE_NET=10.0.0.0/24
|
||||
# host interface to use for upstream connection
|
||||
UPSTREAM_IFACE=${2:-enxe4b97aa99867}
|
||||
|
||||
ip addr add "$USB_IFACE_IP/24" dev "$USB_IFACE"
|
||||
ip link set "$USB_IFACE" up
|
||||
|
||||
iptables -A FORWARD -o "$UPSTREAM_IFACE" -i "$USB_IFACE" -s "$USB_IFACE_NET" -m conntrack --ctstate NEW -j ACCEPT
|
||||
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
||||
iptables -t nat -F POSTROUTING
|
||||
iptables -t nat -A POSTROUTING -o "$UPSTREAM_IFACE" -j MASQUERADE
|
||||
|
||||
echo 1 > /proc/sys/net/ipv4/ip_forward
|
@ -1,21 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
UPSTREAM_IFACE=${1:-en0}
|
||||
USB_IFACE=''
|
||||
USB_IP=${2:-10.0.0.1}
|
||||
|
||||
for i in $(ifconfig -lu); do
|
||||
if ifconfig "$i" | grep -q "${USB_IP}" ; then USB_IFACE=$i; fi;
|
||||
done
|
||||
|
||||
if [ -z "$USB_IFACE" ]
|
||||
then
|
||||
echo "can't find usb interface with ip $USB_IP"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "sharing connecting from upstream interface $UPSTREAM_IFACE to usb interface $USB_IFACE ..."
|
||||
|
||||
sysctl -w net.inet.ip.forwarding=1
|
||||
pfctl -e
|
||||
echo "nat on ${UPSTREAM_IFACE} from ${USB_IFACE}:network to any -> (${UPSTREAM_IFACE})" | pfctl -f -
|
@ -1,22 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
USB_IFACE=$(ifconfig urndis0 | grep urndis0 | awk '{print $1}' | tr -d ':')
|
||||
USB_IP=${2:-10.0.0.1}
|
||||
|
||||
# shellcheck disable=SC2046
|
||||
if test $(whoami) != root; then
|
||||
doas "$0" "$@"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2039
|
||||
if [ "${USB_IFACE}" == "urndis0" ]; then
|
||||
ifconfig "${USB_IFACE}" "${USB_IP}"
|
||||
sysctl -w net.inet.ip.forwarding=1
|
||||
echo "match out on egress inet from ${USB_IFACE}:network to any nat-to (egress:0)" | pfctl -f -
|
||||
pfctl -f /etc/pf.conf
|
||||
echo "sharing connecting from upstream interface to usb interface ${USB_IFACE} ..."
|
||||
else
|
||||
echo "can't find usb interface with ip ${USB_IFACE}"
|
||||
exit 1
|
||||
fi
|
@ -1,217 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
import yaml
|
||||
import toml
|
||||
|
||||
sys.path.insert(0,
|
||||
os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||
'../'))
|
||||
|
||||
import pwnagotchi.ui.faces as faces
|
||||
from pwnagotchi.ui.display import Display
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class CustomDisplay(Display):
|
||||
|
||||
def __init__(self, config, state):
|
||||
self.last_image = None
|
||||
super(CustomDisplay, self).__init__(config, state)
|
||||
|
||||
def _http_serve(self):
|
||||
# do nothing
|
||||
pass
|
||||
|
||||
def _on_view_rendered(self, img):
|
||||
self.last_image = img
|
||||
|
||||
def get_image(self):
|
||||
"""
|
||||
Return the saved image
|
||||
"""
|
||||
return self.last_image
|
||||
|
||||
|
||||
class DummyPeer:
|
||||
|
||||
def __init__(self):
|
||||
self.rssi = -50
|
||||
|
||||
@staticmethod
|
||||
def name():
|
||||
return "beta"
|
||||
|
||||
@staticmethod
|
||||
def pwnd_run():
|
||||
return 50
|
||||
|
||||
@staticmethod
|
||||
def pwnd_total():
|
||||
return 100
|
||||
|
||||
@staticmethod
|
||||
def first_encounter():
|
||||
return 1
|
||||
|
||||
@staticmethod
|
||||
def face():
|
||||
return faces.FRIEND
|
||||
|
||||
|
||||
def append_images(images, horizontal=True, xmargin=0, ymargin=0):
|
||||
w, h = zip(*(i.size for i in images))
|
||||
|
||||
if horizontal:
|
||||
t_w = sum(w)
|
||||
t_h = max(h)
|
||||
else:
|
||||
t_w = max(w)
|
||||
t_h = sum(h)
|
||||
|
||||
result = Image.new('RGB', (t_w, t_h))
|
||||
|
||||
x_offset = 0
|
||||
y_offset = 0
|
||||
|
||||
for im in images:
|
||||
result.paste(im, (x_offset, y_offset))
|
||||
if horizontal:
|
||||
x_offset += im.size[0] + xmargin
|
||||
else:
|
||||
y_offset += im.size[1] + ymargin
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="This program emulates\
|
||||
the pwnagotchi display")
|
||||
parser.add_argument('--displays', help="Which displays to use.", nargs="+", default=["waveshare_2"])
|
||||
parser.add_argument('--lang', help="Language to use", default="en")
|
||||
parser.add_argument('--output', help="Path to output image (PNG)", default="preview.png")
|
||||
parser.add_argument('--show-peer', dest="showpeer", help="This options will show a dummy peer", action="store_true")
|
||||
parser.add_argument('--xmargin', help="Add X-Margin", type=int, default=5)
|
||||
parser.add_argument('--ymargin', help="Add Y-Margin", type=int, default=5)
|
||||
args = parser.parse_args()
|
||||
|
||||
config_template = '''
|
||||
main:
|
||||
lang: {lang}
|
||||
ui:
|
||||
font:
|
||||
name: 'DejaVuSansMono'
|
||||
size_offset: 0
|
||||
size: 0
|
||||
fps: 0.3
|
||||
display:
|
||||
enabled: false
|
||||
rotation: 180
|
||||
color: black
|
||||
refresh: 30
|
||||
type: {display}
|
||||
web:
|
||||
enabled: true
|
||||
address: '::'
|
||||
port: 8080
|
||||
|
||||
faces:
|
||||
look_r: '( ⚆_⚆)'
|
||||
look_l: '(☉_☉ )'
|
||||
look_r_happy: '( ◕‿◕)'
|
||||
look_l_happy: '(◕‿◕ )'
|
||||
sleep: '(⇀‿‿↼)'
|
||||
sleep2: '(≖‿‿≖)'
|
||||
awake: '(◕‿‿◕)'
|
||||
bored: '(-__-)'
|
||||
intense: '(°▃▃°)'
|
||||
cool: '(⌐■_■)'
|
||||
happy: '(•‿‿•)'
|
||||
excited: '(ᵔ◡◡ᵔ)'
|
||||
grateful: '(^‿‿^)'
|
||||
motivated: '(☼‿‿☼)'
|
||||
demotivated: '(≖__≖)'
|
||||
smart: '(✜‿‿✜)'
|
||||
lonely: '(ب__ب)'
|
||||
sad: '(╥☁╥ )'
|
||||
friend: '(♥‿‿♥)'
|
||||
broken: '(☓‿‿☓)'
|
||||
debug: '(#__#)'
|
||||
'''
|
||||
|
||||
list_of_displays = list()
|
||||
for display_type in args.displays:
|
||||
config = yaml.safe_load(config_template.format(display=display_type,
|
||||
lang=args.lang))
|
||||
display = CustomDisplay(config=config, state={'name': f"{display_type}>"})
|
||||
list_of_displays.append(display)
|
||||
|
||||
columns = list()
|
||||
|
||||
for display in list_of_displays:
|
||||
emotions = list()
|
||||
if args.showpeer:
|
||||
display.set_closest_peer(DummyPeer(), 10)
|
||||
display.on_starting()
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_ai_ready()
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_normal()
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_new_peer(DummyPeer())
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_lost_peer(DummyPeer())
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_free_channel('6')
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.wait(2)
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_bored()
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_sad()
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_motivated(1)
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_demotivated(-1)
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_excited()
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_deauth({'mac': 'DE:AD:BE:EF:CA:FE'})
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_miss('test')
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_lonely()
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_handshakes(1)
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
display.on_rebooting()
|
||||
display.update()
|
||||
emotions.append(display.get_image())
|
||||
|
||||
# append them all together (vertical)
|
||||
columns.append(append_images(emotions, horizontal=False, xmargin=args.xmargin, ymargin=args.ymargin))
|
||||
|
||||
# append columns side by side
|
||||
final_image = append_images(columns, horizontal=True, xmargin=args.xmargin, ymargin=args.ymargin)
|
||||
final_image.save(args.output, 'PNG')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
SystemExit(main())
|
@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
rm -rf build dist pwnagotchi.egg-info &&
|
||||
python3 setup.py sdist bdist_wheel &&
|
||||
clear &&
|
||||
twine upload dist/*
|
@ -1,60 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
usage() {
|
||||
echo "Usage: restore.sh [-bhnu] [-h] [-b backup name] [-n host name] [-u user name]"
|
||||
}
|
||||
|
||||
while getopts "hb:n:u:" arg; do
|
||||
case $arg in
|
||||
b)
|
||||
BACKUP=$OPTARG
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
exit
|
||||
;;
|
||||
n)
|
||||
UNIT_HOSTNAME=$OPTARG
|
||||
;;
|
||||
u)
|
||||
UNIT_USERNAME=$OPTARG
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
# name of the ethernet gadget interface on the host
|
||||
UNIT_HOSTNAME=${UNIT_HOSTNAME:-10.0.0.2}
|
||||
# output backup tgz file
|
||||
# shellcheck disable=SC2086
|
||||
if [ -z $BACKUP ]; then
|
||||
# shellcheck disable=SC2012
|
||||
BACKUP=$(ls -rt "${UNIT_HOSTNAME}"-backup-*.tgz 2>/dev/null | tail -n1)
|
||||
if [ -z "$BACKUP" ]; then
|
||||
echo "@ Can't find backup file. Please specify one with '-b'"
|
||||
exit 1
|
||||
fi
|
||||
echo "@ Found backup file:"
|
||||
# shellcheck disable=SC2028
|
||||
echo "\t${BACKUP}"
|
||||
# shellcheck disable=SC2039
|
||||
echo -n "@ continue restroring this file? (y/n) "
|
||||
# shellcheck disable=SC2162
|
||||
read CONTINUE
|
||||
CONTINUE=$(echo "${CONTINUE}" | tr "[:upper:]" "[:lower:]")
|
||||
if [ "${CONTINUE}" != "y" ]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
# username to use for ssh
|
||||
UNIT_USERNAME=${UNIT_USERNAME:-pi}
|
||||
|
||||
ping -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || {
|
||||
echo "@ unit ${UNIT_HOSTNAME} can't be reached, make sure it's connected and a static IP assigned to the USB interface."
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "@ restoring $BACKUP to $UNIT_HOSTNAME ..."
|
||||
# shellcheck disable=SC2002
|
||||
cat "${BACKUP}" | ssh "${UNIT_USERNAME}@${UNIT_HOSTNAME}" "sudo tar xzv -C /"
|
@ -1,290 +0,0 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A script that setups Internet Connection Sharing for Pwnagotchi.
|
||||
|
||||
.DESCRIPTION
|
||||
A script that setups Internet Connection Sharing for Pwnagotchi.
|
||||
|
||||
Note: Internet Connection Sharing on Windows can be a bit unstable on between reboots.
|
||||
You might need to run this script occasionally to disable and re-enable Internet Connection Sharing.
|
||||
|
||||
.PARAMETER EnableInternetConnectionSharing
|
||||
Enable Internet Connection Sharing
|
||||
|
||||
.PARAMETER DisableInternetConnectionSharing
|
||||
Disable Internet Connection Sharing
|
||||
|
||||
.PARAMETER SetPwnagotchiSubnet
|
||||
Change the Internet Connection Sharing subnet to the Pwnagotchi subnet. The USB Gadget Interface IP will default to 10.0.0.1.
|
||||
|
||||
.PARAMETER ScopeAddress
|
||||
Custom ScopeAddress (The IP Address of the USB Gadget Interface.)
|
||||
|
||||
.EXAMPLE
|
||||
# Enable Internet Connection Sharing
|
||||
PS C:\> .\win_connection_share -EnableInternetConnectionSharing
|
||||
|
||||
.EXAMPLE
|
||||
# Disable Internet Connection Sharing
|
||||
PS C:\> .\win_connection_share -DisableInternetConnectionSharing
|
||||
|
||||
.EXAMPLE
|
||||
# Change the regkeys of Internet Connection Sharing to the Pwnagotchi Subnet
|
||||
PS C:\> .\win_connection_share -SetPwnagotchiSubnet
|
||||
|
||||
.EXAMPLE
|
||||
# Change the regkeys of Internet Connection Sharing to the Pwnagotchi Subnet with a custom ScopeAddress (The IP Address of the USB Gadget Interface.)
|
||||
PS C:\> .\win_connection_share -SetPwnagotchiSubnet -ScopeAddress 10.0.0.10
|
||||
#>
|
||||
|
||||
#Requires -Version 5
|
||||
#Requires -RunAsAdministrator
|
||||
[Cmdletbinding()]
|
||||
Param (
|
||||
[switch]$EnableInternetConnectionSharing,
|
||||
[switch]$DisableInternetConnectionSharing,
|
||||
[switch]$SetPwnagotchiSubnet,
|
||||
[ipaddress]$ScopeAddress = '10.0.0.1'
|
||||
)
|
||||
|
||||
# Load helper functions
|
||||
Function Create-HNetObjects {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A helper function that does the heavy lifting with NetCfg.HNetShare
|
||||
|
||||
.DESCRIPTION
|
||||
A helper function that does the heavy lifting with NetCfg.HNetShare. This returns a PSObject containing the `INetSharingConfigurationForINetConnection` info of 2 Adapters.
|
||||
|
||||
.PARAMETER InternetAdaptor
|
||||
The output of Get-NetAdaptor filtered down to the 'main' uplink interface.
|
||||
|
||||
.PARAMETER RNDISGadget
|
||||
The output of Get-NetAdaptor filtered down to the 'USB Ethernet/RNDIS Gadget' interface.
|
||||
|
||||
.EXAMPLE
|
||||
PS> $HNetObject = Create-HNetObjects
|
||||
PS> $HNetObject
|
||||
RNDISIntConfig InternetIntConfig
|
||||
-------------- -----------------
|
||||
System.__ComObject System.__ComObject
|
||||
#>
|
||||
[Cmdletbinding()]
|
||||
Param (
|
||||
$InternetAdaptor = $(Select-NetAdaptor -Message "Please select your main a ethernet adaptor with internet access that will be used for internet sharing."),
|
||||
$RNDISGadget = $(Select-NetAdaptor -Message "Please select your 'USB Ethernet/RNDIS Gadget' adaptor")
|
||||
)
|
||||
Begin {
|
||||
regsvr32.exe /s hnetcfg.dll
|
||||
$HNetShare = New-Object -ComObject HNetCfg.HNetShare
|
||||
}
|
||||
Process {
|
||||
if ($HNetShare.EnumEveryConnection -ne $null) {
|
||||
$InternetInt = $HNetShare.EnumEveryConnection | Where-Object { $HNetShare.NetConnectionProps.Invoke($_).Name -eq ($InternetAdaptor).Name }
|
||||
$InternetIntConfig = $HNetShare.INetSharingConfigurationForINetConnection.Invoke($InternetInt)
|
||||
$RNDISInt = $HNetShare.EnumEveryConnection | Where-Object { $HNetShare.NetConnectionProps.Invoke($_).Name -eq ($RNDISGadget).Name }
|
||||
$RNDISIntConfig = $HNetShare.INetSharingConfigurationForINetConnection.Invoke($RNDISInt)
|
||||
}
|
||||
}
|
||||
End {
|
||||
Return $(New-Object -TypeName PSObject -Property @{InternetIntConfig=$InternetIntConfig;RNDISIntConfig=$RNDISIntConfig;})
|
||||
}
|
||||
}
|
||||
Function Enable-InternetConnectionSharing {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Enables internet connection sharing between the 'main' uplink interface and the 'USB Ethernet/RNDIS Gadget' interface.
|
||||
|
||||
.DESCRIPTION
|
||||
Enables internet connection sharing between the 'main' uplink interface and the 'USB Ethernet/RNDIS Gadget' interface.
|
||||
|
||||
.EXAMPLE
|
||||
PS> Enable-InternetConnectionSharing
|
||||
|
||||
#>
|
||||
[Cmdletbinding()]
|
||||
$HNetObject = Create-HNetObjects
|
||||
$HNetObject.InternetIntConfig.EnableSharing(0)
|
||||
$HNetObject.RNDISIntConfig.EnableSharing(1)
|
||||
Write-Output "[x] Enabled Internet Connection Sharing."
|
||||
}
|
||||
Function Disable-InternetConnectionSharing {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Disables internet connection sharing between the 'main' uplink interface and the 'USB Ethernet/RNDIS Gadget' interface.
|
||||
|
||||
.DESCRIPTION
|
||||
Disables internet connection sharing between the 'main' uplink interface and the 'USB Ethernet/RNDIS Gadget' interface.
|
||||
|
||||
.EXAMPLE
|
||||
PS> Disable-InternetConnectionSharing
|
||||
|
||||
#>
|
||||
[Cmdletbinding()]
|
||||
$HNetObject = $(Create-HNetObjects)
|
||||
$HNetObject.InternetIntConfig.DisableSharing()
|
||||
$HNetObject.RNDISIntConfig.DisableSharing()
|
||||
Write-Output "[x] Disabled Internet Connection Sharing."
|
||||
}
|
||||
Function Test-PwnagotchiSubnet {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests the registry for the correct ScopeAddress.
|
||||
|
||||
.DESCRIPTION
|
||||
Tests the registry for the correct ScopeAddress. By default windows uses a 192.168.137.x subnet for Internet Connection Sharing. This value can be changed
|
||||
in the registry.
|
||||
|
||||
.EXAMPLE
|
||||
PS> Test-PwnagotchiSubnet
|
||||
[!] By default Internet Connection Sharing uses a 192.168.137.x subnet. Run Set-PwnagotchiSubnet to ensure you and your little friend are on the same subnet.
|
||||
#>
|
||||
[Cmdletbinding()]
|
||||
$RegKeys = Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters -ErrorAction Stop
|
||||
If ($RegKeys.ScopeAddress -notmatch '10.0.0.') {
|
||||
Write-Error "By default Internet Connection Sharing uses a 192.168.137.x subnet. Run Set-PwnagotchiSubnet to ensure you and your little friend are on the same subnet." -ErrorAction Stop
|
||||
}
|
||||
If ($RegKeys.ScopeAddressBackup -notmatch '10.0.0.') {
|
||||
Write-Error "By default Internet Connection Sharing uses a 192.168.137.x subnet. Run Set-PwnagotchiSubnet to ensure you and your little friend are on the same subnet." -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
Function Set-PwnagotchiSubnet {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Set the registry for the correct ScopeAddress.
|
||||
|
||||
.DESCRIPTION
|
||||
Set the registry for the correct ScopeAddress. By default windows uses a 192.168.137.x subnet for Internet Connection Sharing. This value can be changed
|
||||
in the registry. By default it will be changed to 10.0.0.1
|
||||
|
||||
.PARAMETER ScopeAddress
|
||||
The IP address the USB Gadget interface should use.
|
||||
|
||||
.EXAMPLE
|
||||
Set-PwnagotchiSubnet
|
||||
|
||||
#>
|
||||
[Cmdletbinding()]
|
||||
Param (
|
||||
$ScopeAddress = '10.0.0.1'
|
||||
)
|
||||
Try {
|
||||
[void]([ipaddress]$ScopeAddress)
|
||||
[void]([byte[]] $ScopeAddress.split('.'))
|
||||
} Catch {
|
||||
Write-Error "$ScopeAddress is not a valid IP."
|
||||
}
|
||||
Try {
|
||||
Set-ItemProperty -Name ScopeAddress -Path "HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\" -Value $ScopeAddress -ErrorAction Stop
|
||||
Set-ItemProperty -Name ScopeAddressBackup -Path "HKLM:\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\" -Value $ScopeAddress -ErrorAction Stop
|
||||
Write-Warning "The Internet Connection Sharing subnet has been updated. A reboot of windows is required !"
|
||||
} Catch {
|
||||
$PSCmdlet.ThrowTerminatingError($PSItem)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# Main Function
|
||||
Function Setup-PwnagotchiNetwork {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Function to setup networking.
|
||||
|
||||
.DESCRIPTION
|
||||
Function to setup networking. Main function calls helpers functions.
|
||||
|
||||
.PARAMETER EnableInternetConnectionSharing
|
||||
Enable Internet Connection Sharing
|
||||
|
||||
.PARAMETER DisableInternetConnectionSharing
|
||||
Disable Internet Connection Sharing
|
||||
|
||||
.PARAMETER SetPwnagotchiSubnet
|
||||
Change the Internet Connection Sharing subnet to the Pwnagotchi. Defaults to 10.0.0.1.
|
||||
|
||||
.PARAMETER ScopeAddress
|
||||
Custom ScopeAddress (the ICS ip address)
|
||||
|
||||
.EXAMPLE
|
||||
PS> Setup-PwnagotchiNetwork -EnableInternetConnectionSharing
|
||||
|
||||
#>
|
||||
|
||||
Param (
|
||||
[switch]$EnableInternetConnectionSharing,
|
||||
[switch]$DisableInternetConnectionSharing,
|
||||
[switch]$SetPwnagotchiSubnet,
|
||||
$ScopeAddress = '10.0.0.1'
|
||||
)
|
||||
Begin {
|
||||
Try {
|
||||
Write-Debug "Begin"
|
||||
$ErrorSplat=@{ErrorAction="stop"}
|
||||
Write-Debug "Testing subnet"
|
||||
Try {
|
||||
Test-PwnagotchiSubnet @ErrorSplat
|
||||
} Catch {
|
||||
If ($SetPwnagotchiSubnet) {
|
||||
Write-Debug "Setting subnet"
|
||||
Set-PwnagotchiSubnet -ScopeAddress $ScopeAddress @ErrorSplat
|
||||
} Else {
|
||||
Write-Error "By default Internet Connection Sharing uses a 192.168.137.x subnet. Run this script with the -SetPwnagotchiSubnet to setup the network." -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
} Catch {
|
||||
$PSCmdlet.ThrowTerminatingError($PSItem)
|
||||
}
|
||||
}
|
||||
Process {
|
||||
Write-Debug "Process"
|
||||
Try {
|
||||
If ($EnableInternetConnectionSharing) {
|
||||
Write-Debug "Enable network Sharing"
|
||||
Enable-InternetConnectionSharing @ErrorSplat
|
||||
} ElseIf ($DisableInternetConnectionSharing) {
|
||||
Write-Debug "Disable network Sharing"
|
||||
Disable-InternetConnectionSharing @ErrorSplat
|
||||
}
|
||||
} Catch {
|
||||
$PSCmdlet.ThrowTerminatingError($PSItem)
|
||||
}
|
||||
}
|
||||
End {
|
||||
Write-Debug "End"
|
||||
Try {
|
||||
# Nothing to return.
|
||||
} Catch {
|
||||
$PSCmdlet.ThrowTerminatingError($PSItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
Function Select-NetAdaptor {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A menu function to select the correct network adaptors.
|
||||
|
||||
.DESCRIPTION
|
||||
A menu function to select the correct network adaptors.
|
||||
|
||||
.PARAMETER Message
|
||||
Message that will be displayed during the question.
|
||||
|
||||
#>
|
||||
|
||||
Param (
|
||||
$Message
|
||||
)
|
||||
$Adaptors = Get-NetAdapter | Where-Object {$_.MediaConnectionState -eq 'Connected'} | Sort-Object LinkSpeed -Descending
|
||||
do {
|
||||
Write-Host $Message
|
||||
$index = 1
|
||||
foreach ($Adaptor in $Adaptors) {
|
||||
Write-Host "[$index] $($Adaptor.Name), $($Adaptor.InterfaceDescription)"
|
||||
$index++
|
||||
}
|
||||
$Selection = Read-Host "Number"
|
||||
} until ($Adaptors[$selection-1])
|
||||
Return $Adaptors[$selection-1]
|
||||
}
|
||||
# Dynamically create params for Setup-PwnagotchiNetwork function based of param input of script.
|
||||
Setup-PwnagotchiNetwork @psBoundParameters
|
Reference in New Issue
Block a user