portmgr.c
1 #include <stdio.h> 2 3 #define IPTABLES "/sbin/iptables" 4 5 int main(int argc, char *argv[]) 6 { 7 char *iptables_argv[512] = { 8 IPTABLES, "-tnat" 9 }; 10 int i = 2; 11 if (argc >= 2) { 12 switch(*argv[1]) { 13 case ‘a‘: iptables_argv[i++] = "-A"; break; 14 case ‘d‘: iptables_argv[i++] = "-D"; break; 15 default: iptables_argv[i++] = "--line-numbers"; iptables_argv[i++] = "-nvL"; 16 } 17 iptables_argv[i++] = "prerouting_port_forwarding"; 18 int j; 19 for(j = 2; j<argc; ++j) 20 iptables_argv[i++] = argv[j]; 21 return execv(IPTABLES, iptables_argv); 22 } 23 return 0; 24 }
portmgr.php
1 switch($_SERVER["REQUEST_METHOD"]) { 2 case "GET": 3 echo "<body><pre>"; 4 passthru("./portmgr l"); 5 echo "</pre></body>"; 6 exit; 7 case "POST": 8 switch($_POST["cmd"]) { 9 case "a": 10 if ($_POST["dport"] && !empty($_POST["to"])) { 11 //if ($_POST["dport"] === "80" || $_POST["dport"] === "http") { 12 // $msg = "不能为80(http)端口"; 13 // break; 14 //} else 15 $proto = " -p tcp --dport " . $_POST["dport"]; 16 if (!empty($_POST["dst"])) $dst = "-d ". $_POST["dst"]; 17 else $dst = ""; 18 passthru("./portmgr a " . $dst . $proto . " -j DNAT --to " . $_POST["to"], $ret); 19 if ($ret === 0) $msg = "操作成功"; 20 } 21 break; 22 case "d": 23 if (!empty($_POST["id"])) { 24 passthru("./portmgr d " . $_POST["id"], $ret); 25 if ($ret === 0) $msg = "操作成功"; 26 } 27 break; 28 } 29 break; 30 }
时间: 2024-10-26 07:43:46