Skip to content

Instantly share code, notes, and snippets.

@anthonykava
Forked from mainframed/dosbox_ppp.sh
Last active December 21, 2023 00:58
Show Gist options
  • Save anthonykava/5948001068b34c59aae1a5b65154dd67 to your computer and use it in GitHub Desktop.
Save anthonykava/5948001068b34c59aae1a5b65154dd67 to your computer and use it in GitHub Desktop.
This script lets you connect Windows 3.11 to the internet with PPP and Trumpet WinSock in DOSBox
#!/bin/bash
#
# [------------------------------------------------------------------------------------------------]
# [ modified from (legend!) Soldier of FORTRAN's script to work in my testing on Ubuntu 20.04 ]
# [ intended, if it be the will of the demo gads, for a my talk entitled, ]
# [ "the root password was klondike" at kernelcon 2022, https://kernelcon.org ]
# [------------------------------------------------------------------------------------------------]
# [ stolen de: ]
# [ https://gist.github.com/mainframed/2300903d9cc259a2a2ab431ca152dffc ]
# [ also see: ]
# [ https://mainframed767.tumblr.com/post/164524161692/dosbox-and-trump-winsock-together-at-last ]
# [------------------------------------------------------------------------------------------------]
# [ @anthonykava https://forensic.coffee 2022-03-26 ]
# [------------------------------------------------------------------------------------------------]
#
# Heavily Modified from: https://www.dosbox.com/wiki/PPP_configuration_on_linux_host
#
# Usage:
# sudo ./isp.sh
#
# This script makes it so you can browse the net with DOSBox and Trumpet Winsock in
# Windows 3.11
#
# LINUX:
# To use this script simply change the IP addresses below to two unused IP addresses on your network
# then run with root (needed for port 23/proxyarp)
#
# WINDOWS 3.11:
# Install Trumpet Winsock
# Click on 'Dialer->Manual Login'
# Type: AT (if you see 'ERROR' type AT again)
# ATDT <LINUX IP ADDRESS>
# e.g. ATDT 127.0.0.1
# You should see 'CONNECT'
# Hit the Escape button and your good to go!
#
# DOSBox Config:
# Add this to the bottom of your config
# [serial]
# serial1=modem listenport:2323
# serial2=dummy
# serial3=disabled
# serial4=disabled
# ----------------------------
# ,.-='{ sOmE vAriAbLeS }`=-.,
#
ifMasq="enp3s0"
ipHost="10.10.0.200"
ipGuest="10.10.0.201"
mockTTY="/tmp/trumpet"
portTTY="23"
#
# ----------------------------
# check for rootage [ needed to listen on port 23 and work with ppp0 ]
if [ $(id -u) -ne 0 ]; then
echo -e "\nwe will need to be root for this sort of business, try again mit sudo\n"
exit 1
fi
# beware: enables kernel IPv4 forwarding
grep -q 1 /proc/sys/net/ipv4/ip_forward || \
( echo 1 >/proc/sys/net/ipv4/ip_forward )
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT
function ctrl_c() {
echo "** Trapped CTRL-C"
echo "** Shutting down ISP"
echo "** Goodbye 1995"
pkill -9 pppd
[ -e "$Serial" ] && rm "$Serial"
iptables -D FORWARD -s "${ipGuest}" -m comment \
--comment "forward dosbox traffic" -j ACCEPT >/dev/null 2>&1
iptables -D FORWARD -d "${ipGuest}" -m conntrack --ctstate ESTABLISHED,RELATED -m comment \
--comment "forward dosbox related traffic" -j ACCEPT >/dev/null 2>&1
iptables -t nat -D POSTROUTING -s "${ipGuest}" -o "${ifMasq}" -m comment \
--comment "masquerade dosbox traffic" -j MASQUERADE >/dev/null 2>&1
exit 0
}
echo "SoF Presents:"
echo " 1995 ISP Simulator"
echo "Starting Simulator:"
echo " ____ _______ _____ _______ -------
/ __ \ |__ __| / _ \ |__ __| -====------
| (__) | | | \ \ \_\ | | -======------
| __ | | | / \ __ | | --====-------
| | | | | | | (\ / / | | -----------
|_| |_| |_| \_____/ |_| -------"
echo "** Creating fake ISP"
echo "** Using Serial ${mockTTY}"
while true
do
if sleep 0.1 && pgrep socat > /dev/null 2>&1; then
sleep 0.1
else
echo "** Starting socat listener on port ${portTTY}"
socat TCP4-LISTEN:${portTTY} PTY,link="${mockTTY}" &
fi
sleep 0.5
if pgrep pppd > /dev/null 2>&1; then
sleep 1
elif [ -e "${mockTTY}" ]; then
#pppd "/tmp/trumpet" defaultroute mtu 576 10.10.0.200:10.10.0.201 login proxyarp #> /dev/null 2>&1
iptables -D FORWARD -s "${ipGuest}" -m comment \
--comment "forward dosbox traffic" -j ACCEPT >/dev/null 2>&1
iptables -I FORWARD -s "${ipGuest}" -m comment \
--comment "forward dosbox traffic" -j ACCEPT
iptables -D FORWARD -d "${ipGuest}" -m conntrack --ctstate ESTABLISHED,RELATED -m comment \
--comment "forward dosbox related traffic" -j ACCEPT >/dev/null 2>&1
iptables -I FORWARD -d "${ipGuest}" -m conntrack --ctstate ESTABLISHED,RELATED -m comment \
--comment "forward dosbox related traffic" -j ACCEPT
iptables -t nat -D POSTROUTING -s "${ipGuest}" -o "${ifMasq}" -m comment \
--comment "masquerade dosbox traffic" -j MASQUERADE >/dev/null 2>&1
iptables -t nat -I POSTROUTING -s "${ipGuest}" -o "${ifMasq}" -m comment \
--comment "masquerade dosbox traffic" -j MASQUERADE
pppd "${mockTTY}" 57600 ${ipHost}:${ipGuest} \
defaultroute mtu 576 login proxyarp noauth ms-dns 1.1.1.1 >/dev/null 2>&1
# ^-- worked for me on Ubuntu 20.04, stock packages as of 2022-03-26, (@anthonykava)
# ^- had to set DNS in Trumpet Winsock (v3.0D) manually despite ms-dns and best wishes
fi
done
#vim: set ts=4 sw=4 sts=4 noet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment