flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > udp port 67, multiple listener in windows 11

Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 13394
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 25 Apr 2025, 19:49
in windows cmd.exe
Code:
C:\Windows\System32>netstat -anb | findstr ":67"
 UDP    172.25.64.1:67         *:*
    

that ip is hyper-v default switch, and the process belong to ics, under service name SharedAccess

i downloaded tiny dhcp server, https://softcab.com/archive/dhcp-server.php and run it
Code:
C:\Windows\System32>netstat -anb | findstr ":67"
  UDP    172.25.64.1:67         *:*
  UDP    172.25.64.1:67         *:*
  UDP    192.168.43.220:67      *:*
    

now we can see both are listening 67 udp, so i tried to use golang and write a dhcp that listen udp port 67 but denied,
Code:
Found interface 'vEthernet (Default Switch)' with IP address: 172.25.64.1
Failed to listen on 172.25.64.1:67: listen udp4 172.25.64.1%vEthernet (Default Switch):67: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
    

so how come it can listen, but my program can't?

Image
Post 25 Apr 2025, 19:49
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1158
Location: Russia
macomics 25 Apr 2025, 20:33
Most likely, one of the processes received a copy of the handle after creation with InheritHandles=True
Two ports in the same process are open on different system interfaces.
Post 25 Apr 2025, 20:33
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13394
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 26 Apr 2025, 22:39
i tested the following, listening in 0.0.0.0

i can receive discover from hyper-v client since it posted to broadcast, but to offer it from 0.0.0.0 is possible or impossible idk yet, do i need to bind hyper-v gateway in this case 172.25.64.1 to offer 172.25.64.100?

btw, am using

"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/insomniacslk/dhcp/dhcpv4/server4"
Post 26 Apr 2025, 22:39
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13394
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 15 May 2025, 21:46
i found a new way to doing this without coding, by using a loop adapter, wireguard and new-netnat ps command

but too bad, it doesnt seem to bypass isp hotspot restrictions,

still finding ways to accomplish this objective
Post 15 May 2025, 21:46
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13394
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 16 May 2025, 05:20
wireguard, every proxy, seems to accomplish what i wanted, but not so stable, more testing required
Post 16 May 2025, 05:20
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13394
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 16 May 2025, 18:49
i figured out, maybe the seamless and easiest method would be getting an old phone and rooted it, Laughing
Post 16 May 2025, 18:49
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13394
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 27 May 2025, 02:02
just found the magic, no need root,

1. install f-droid, termux
2. install golang
3. the write a http/s proxy using gemini, golang, build and run

Code:
package main

import (
        "io"
        "log"
        "net" // Still needed for net.DialTimeout and Hijacker related types
        "net/http"
        "time"
)

// A simple HTTP/HTTPS proxy handler
func proxyHandler(w http.ResponseWriter, r *http.Request) {
        // r.RemoteAddr is already a string (e.g., "192.168.1.50:12345")
        clientIPString := r.RemoteAddr
        log.Printf("Proxying request from %s: %s %s", clientIPString, r.Method, r.URL.String())

        // Handle HTTPS (CONNECT method)
        if r.Method == http.MethodConnect {
                handleHTTPS(w, r, clientIPString) // Pass the string directly
                return
        }

        // Handle HTTP
        handleHTTP(w, r, clientIPString) // Pass the string directly
}

// handleHTTPS establishes a tunnel for HTTPS traffic
func handleHTTPS(w http.ResponseWriter, r *http.Request, clientIPString string) { // Corrected type to string
        // Connect to the target host
        destConn, err := net.DialTimeout("tcp", r.Host, 10*time.Second) // r.Host is like "google.com:443"
        if err != nil {
                log.Printf("HTTPS Error: Could not connect to %s from %s: %v", r.Host, clientIPString, err) // Use string directly
                http.Error(w, err.Error(), http.StatusServiceUnavailable)
                return
        }
        defer destConn.Close()

        // Tell the client that the tunnel is established
        w.WriteHeader(http.StatusOK) // Sends HTTP/1.1 200 OK

        // Hijack the client connection to directly tunnel bytes
        hijacker, ok := w.(http.Hijacker)
        if !ok {
                log.Printf("HTTPS Error: Hijacking not supported for client %s", clientIPString) // Use string directly
                http.Error(w, "Hijacking not supported", http.StatusInternalServerError)
                return
        }
        clientConn, _, err := hijacker.Hijack()
        if err != nil {
                log.Printf("HTTPS Error: Hijack failed for client %s: %v", clientIPString, err) // Use string directly
                http.Error(w, err.Error(), http.StatusInternalServerError)
                return
        }
        defer clientConn.Close()

        log.Printf("HTTPS Tunnel established for %s to %s", clientIPString, r.Host) // Use string directly

        // Bidirectional copy between client and destination
        go io.Copy(destConn, clientConn)
        io.Copy(clientConn, destConn) // Block until connection closes
}

// handleHTTP forwards regular HTTP requests
func handleHTTP(w http.ResponseWriter, r *http.Request, clientIPString string) { // Corrected type to string
        // Create a new HTTP client
        client := &http.Client{
                Timeout: 30 * time.Second, // Set a timeout for the client request
        }

        // Create a new request to the target
        req := r.Clone(r.Context())
        req.RequestURI = "" // RequestURI must be empty for client requests

        // Ensure Host header is handled correctly
        if r.Host != "" {
                req.Host = r.Host
        } else if r.URL.Host != "" {
                req.Host = r.URL.Host
        }


        // Make the request to the target
        resp, err := client.Do(req)
        if err != nil {
                log.Printf("HTTP Error: Could not forward request from %s to %s: %v", clientIPString, req.URL.String(), err) // Use string directly
                http.Error(w, err.Error(), http.StatusBadGateway)
                return
        }
        defer resp.Body.Close()

        // Copy headers from target response to client response
        for name, values := range resp.Header {
                for _, value := range values {
                        w.Header().Add(name, value)
                }
        }

        // Set the status code
        w.WriteHeader(resp.StatusCode)

        // Copy the body from target response to client response
        bytesCopied, err := io.Copy(w, resp.Body)
        if err != nil {
                log.Printf("HTTP Error: Failed to copy response body from %s to client %s: %v", req.URL.String(), clientIPString, err) // Use string directly
        } else {
                log.Printf("HTTP Success: %s %s -> %s (Bytes: %d) for client %s", r.Method, r.URL.String(), resp.Status, bytesCopied, clientIPString) // Use string directly
        }
}

func main() {
        listenAddr := ":8080"
        log.Printf("Starting HTTP/HTTPS Proxy server on %s", listenAddr)
        log.Println("Note: This proxy does not implement caching, authentication, or advanced features.")
        log.Println("Ensure your device allows incoming connections on this port.")

        server := &http.Server{
                Addr:    listenAddr,
                Handler: http.HandlerFunc(proxyHandler), // Our custom handler
                ReadTimeout:  10 * time.Second,
                WriteTimeout: 10 * time.Second,
                IdleTimeout:  60 * time.Second,
        }

        if err := server.ListenAndServe(); err != nil {
                log.Fatalf("Failed to start proxy server: %v", err)
        }
}
    


you can connect another device into this by setting manual proxy in the wifi connection,

Quote:
2025/05/27 02:01:59 Proxying request from 192.168.122.144:65176: CONNECT //board.flatassembler.net:443
2025/05/27 02:01:59 HTTPS Tunnel established for 192.168.122.144:65176 to board.flatassembler.net:443
Post 27 May 2025, 02:02
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.