Skip to content

Instantly share code, notes, and snippets.

@doorbash
Last active October 23, 2022 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doorbash/b3ee3d5a64d8c8ff7c1e37873b29d77f to your computer and use it in GitHub Desktop.
Save doorbash/b3ee3d5a64d8c8ff7c1e37873b29d77f to your computer and use it in GitHub Desktop.
openwrt fake connectivity check server for android/ios

Download upx:

https://github.com/upx/upx/releases/download/v3.93/upx-3.93-amd64_linux.tar.xz

Compile and compress:

GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -trimpath -ldflags="-s -w" -o generate_204
upx -9 ./generate_204

move it to /bin/ and make it executable: chmod +x /bin/generate_204

Create ~/g204_run_loop.sh:

#!/bin/sh
while true
do
    generate_204
done > /dev/null

Install nohub:

opkg update
opkg install coreutils-nohup

Add to /etc/rc.local:

iptables -t nat -A PREROUTING -i wlan0 -p tcp -d 10.0.0.1 --dport 80 -j REDIRECT --to-port 8080

nohup /root/g204_run_loop.sh >/dev/null 2>&1 &

Edit /etc/config/dhcp:

config dnsmasq
...
list address '/android.com/10.0.0.1'
list address '/google.com/10.0.0.1'
list address '/gstatic.com/10.0.0.1'
list address '/apple.com/10.0.0.1'


config dhcp 'wifi'
list dhcp_option '6,192.168.43.1'

Restart dnsmasq:

/etc/init.d/dnsmasq restart

Update

Or:

iptables -P FORWARD DROP
iptables -A FORWARD -i wlan0 -p udp -d 8.8.8.8 --dport 53 -j ACCEPT
iptables -A FORWARD -i wlan0 -p tcp -d google_ip_here --match multiport --dports 80,443 -j ACCEPT
iptables -A FORWARD -o wlan0 -j ACCEPT
config dhcp 'wifi'
list dhcp_option '6,8.8.8.8'
package main
import (
"io"
"log"
"net/http"
"os"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func iosSuccess(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("<!DOCTYPE HTML><HTML><HEAD><TITLE>Success</TITLE></HEAD><BODY>Success</BODY></HTML>"))
}
func generate204(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
}
func main() {
r := mux.NewRouter()
r.Use(func(h http.Handler) http.Handler {
return handlers.CustomLoggingHandler(os.Stdout, h, func(writer io.Writer, params handlers.LogFormatterParams) {
log.Println("HttpLogger:", params.Request.RemoteAddr, params.Request.Method, params.Request.URL.Path, params.StatusCode)
})
})
r.HandleFunc("/hotspot-detect.html", iosSuccess)
r.HandleFunc("/gen_204", generate204)
r.HandleFunc("/generate_204", generate204)
if err := http.ListenAndServe(":8080", r); err != nil {
log.Println(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment