03 กุมภาพันธ์ 2566

PHP Cloudflare Turnstile

Turnstile is Cloudflare’s smart CAPTCHA alternative.

https://www.cloudflare.com/products/turnstile/

<?php
if (isset($_POST["cf-turnstile-response"])) {

    $captcha = $_POST['cf-turnstile-response'];
    $secretKey = "__Secret_Key__";
    $ip = $_SERVER['REMOTE_ADDR'];
    $url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
    $data = array('secret' => $secretKey, 'response' => $captcha, 'remoteip' => $ip);

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $curlData = curl_exec($curl);
    curl_close($curl);
    
    $result = json_decode($curlData, true);
    
    if (intval($result["success"]) == 1) {
        echo "success";
        exit();
    } else {
        echo "error";
        exit();
    }
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Test Turnstile</title>
        <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
    </head>
    <body>
        <form method="POST" action="">
            <div>
                <!-- The following line controls and configures the Turnstile widget. -->
                <div class="cf-turnstile" data-sitekey="__Site_Key__" data-theme="light"></div>
                <!-- end. -->
            </div>
            <button  type="submit">Sign in</button>
        </form>
    </body>
</html>

26 มกราคม 2566

Mikrotik load balance with recursive route

RouterOS7

ehter1 : 192.168.1.x/24
ether2 : 192.168.2.x/24
LAN : 192.168.25.1/24

ether1 ping check : 1.0.0.1
ether2 ping check : 8.8.4.4

/ip firewall mangle
add action=accept chain=prerouting dst-address=192.168.1.0/24
add action=accept chain=prerouting dst-address=192.168.2.0/24
add action=accept chain=prerouting dst-address=192.168.25.0/24
add action=mark-connection chain=input in-interface=ether1 new-connection-mark=wan1_input passthrough=yes
add action=mark-connection chain=input in-interface=ether2 new-connection-mark=wan2_input passthrough=yes
add action=mark-routing chain=output comment="WAN1 Input" connection-mark=wan1_input new-routing-mark=WAN1 passthrough=no
add action=mark-routing chain=output comment="WAN2 Input" connection-mark=wan2_input new-routing-mark=WAN2 passthrough=no
add action=mark-connection chain=prerouting in-interface=ether1 new-connection-mark=wan1_conn passthrough=yes
add action=mark-connection chain=prerouting in-interface=ether2 new-connection-mark=wan2_conn passthrough=yes
add action=mark-routing chain=prerouting connection-mark=wan1_conn in-interface=br-lan new-routing-mark=WAN1 passthrough=no
add action=mark-routing chain=prerouting connection-mark=wan2_conn in-interface=br-lan new-routing-mark=WAN2 passthrough=no
add action=mark-connection chain=prerouting comment=4/0 dst-address-type=!local in-interface=br-lan new-connection-mark=wan1_lb passthrough=yes per-connection-classifier=both-addresses:4/0
add action=mark-connection chain=prerouting comment=4/1 dst-address-type=!local in-interface=br-lan new-connection-mark=wan2_lb passthrough=yes per-connection-classifier=both-addresses:4/1
add action=mark-connection chain=prerouting comment=4/2 dst-address-type=!local in-interface=br-lan new-connection-mark=wan1_lb passthrough=yes per-connection-classifier=both-addresses:4/2
add action=mark-connection chain=prerouting comment=4/3 dst-address-type=!local in-interface=br-lan new-connection-mark=wan2_lb passthrough=yes per-connection-classifier=both-addresses:4/3
add action=mark-routing chain=prerouting connection-mark=wan1_lb in-interface=br-lan new-routing-mark=WAN1 passthrough=no
add action=mark-routing chain=prerouting connection-mark=wan2_lb in-interface=br-lan new-routing-mark=WAN2 passthrough=no

/queue simple
add dst=ether1 limit-at=1M/1M max-limit=10M/10M name=wan1 queue=pcq-upload-default/pcq-download-default target=192.168.25.0/24
add dst=ether2 limit-at=1M/1M max-limit=10M/10M name=wan2 queue=pcq-upload-default/pcq-download-default target=192.168.25.0/24

/ip route
add distance=1 dst-address=1.0.0.1/32 gateway=192.168.1.1 routing-table=main scope=10
add distance=1 dst-address=8.8.4.4/32 gateway=192.168.2.1 routing-table=main scope=10
add check-gateway=ping distance=1 dst-address=0.0.0.0/0 gateway=1.0.0.1 routing-table=main target-scope=30
add check-gateway=ping distance=1 dst-address=0.0.0.0/0 gateway=8.8.4.4 routing-table=main target-scope=30
add check-gateway=ping distance=1 dst-address=0.0.0.0/0 gateway=1.0.0.1 routing-table=WAN1 target-scope=30
add check-gateway=ping distance=1 dst-address=0.0.0.0/0 gateway=8.8.4.4 routing-table=WAN2 target-scope=30

25 ธันวาคม 2565

Kali Linux TP-Link TP-W772N V.4

Kali Linux 2022.4
rtl8188eus v5.3.9

# apt update && apt -y upgrade
# apt install bc
# apt install linux-headers-$(uname -r)
# apt install dkms
# rmmod r8188eu.ko
# echo "blacklist r8188eu" >> "/etc/modprobe.d/realtek.conf"
# reboot
# git clone https://github.com/aircrack-ng/rtl8188eus
# cd rtl8188eus
# sed -i 's/$(srctree)\/$(src)/$(pwd)\/$(src)/'g Makefile
# make
# make install 
# modprobe 8188eu

20 ธันวาคม 2565

Mikrotik script :: Add default route to wireguard for dynamic wan ip

RouterOS7

wireguard server public ip 10.0.0.1
wireguard server private ip 192.168.0.1

/ip route add dst-address=0.0.0.0/0 gateway=192.168.0.1 scope=10 check-gateway=ping

Change dhcp-client "Default Route Distance" to 5 
#### script dhcp-client

:if ($bound=1) do={    
    /ip route remove [/ip route find comment="route-wireguard-wan"]
    /ip route add gateway=$"gateway-address" dst-address="10.0.0.1" scope=10  comment="route-wireguard-wan"
} else={
    /ip route remove [/ip route find comment="route-wireguard-wan"]
}

21 พฤศจิกายน 2565

Mikrotik 2 WAN failover with recursive routing

RouterOS7

WAN1 port ether1 gateway 192.168.1.1
WAN2 port ehter2 gateway 192.168.2.1

/ip/address/
add address=192.168.1.2/24 interface=ether1
add address=192.168.2.2/24 interface=ether2


/ip/route/
add dst-address=1.0.0.1 gateway=192.168.1.1 scope=10 comment="Recursive WAN1"
add dst-address=8.8.4.4 gateway=192.168.2.1 scope=10 comment="Recursive WAN2"
add gateway=1.0.0.1 check-gateway=ping distance=1 target-scope=30 comment="Route WAN1"
add gateway=8.8.4.4 check-gateway=ping distance=2 target-scope=30 comment="Route WAN2"

/ip/firewall/nat/
add chain=srcnat out-interface=ether1 action=masquerade comment="NAT WAN1"
add chain=srcnat out-interface=ether2 action=masquerade comment="NAT WAN2"

Mikrotik Quad9 DOH (update 2024)

RouterOS 7 

/ip/dns/ set servers=9.9.9.9,149.112.112.112

/tool/fetch mode=https url="https://cacerts.digicert.com/DigiCertGlobalG3TLSECCSHA3842020CA1-1.crt.pem"

/certificate/import file-name=DigiCertGlobalG3TLSECCSHA3842020CA1-1.crt.pem name=DigiCertGlobalG3TLSECCSHA3842020CA1-1.crt

/ip/dns/ set use-doh-server=https://dns.quad9.net/dns-query verify-doh-cert=yes allow-remote-requests=yes

/tool/sniffer/quick port=53,443 ip-address=9.9.9.9,149.112.112.112


https://docs.quad9.net/Setup_Guides/Open-Source_Routers/MikroTik_RouterOS_%28Encrypted%29/

21 ตุลาคม 2565

OpenWrt wifi client bridge

Xiaomi Redmi Router AC2100
OpenWrt 22.03.0

In some cases, the wireless drivers used in OpenWrt do not support “Layer 2” bridging in client mode with a specific “upstream” wireless system. When this occurs, one approach is to route the traffic between LAN and the upstream wireless system. Broadcast traffic, such as DHCP and link-local discovery like mDNS are generally not routable. 

LAN Interface
Reset the router to return to default openwrt settings.
Connect a computer to a LAN port and log into LuCI web UI at 192.168.1.1.
Network -> Interfaces -> LAN -> General Settings
Assign an IP address in a different subnet (e.g. 192.168.11.1). Click Save.
Network -> Interfaces -> LAN -> DHCP Server -> General Setup
Check Ignore interface to disable DHCP for the LAN interface.
Network -> Interfaces -> LAN -> DHCP Server -> IPv6 Settings
RA-Service set disabled.
DHCPv6-Service set disabled.
Click Save.
Click Save & apply.
Connect a computer to a LAN port and log into LuCI web UI at 192.168.11.1.
it is recommended to delete the redundant WAN interfaces and firewall zones. 

Wi-Fi
Network -> Wireless
click on Scan button for the desired radio.
Choose the Wi-Fi network you want to connect to from the page and click Join Network.
Enter the Wi-Fi password and select lan firewall zone.
Click Sunmit.
Click Save.
Click Save & Apply.

Installing relayd package
System -> Software
Click Update List button.
Enter luci-proto-relay into the Filter box, and click Install.
Important: Reboot the router.

Creating Relay Interface
Network -> Interfaces
Click on Add New Interface.
Enter a name and select Relay bridge protocol
Click Create Interface
Enter the IP address of WWAN interface.
Select both lan and wwan in the Relay between networks list.
Click Save.
Click Save & Apply.
After you have completed above steps, reboot the router.
Reminder: Remove the static IP address from your computer. ie. change it back to DHCP client mode.
When the Wifi bridge is powered up, your computer should acquire DHCP IP address from your main router.
The Wifi bridge can be managed through its static wwan IP address.

ref :: https://openwrt.org/docs/guide-user/network/wifi/relay_configuration