乐于分享
好东西不私藏

利用FOFA网络空间测绘查询酒店地址及源码

利用FOFA网络空间测绘查询酒店地址及源码

   首先要在https://fofa.info/注册帐号,然后登陆,复制cookie查询。
效果图:
查询地址:https://nbhg.537224.xyz/fofa/
也可以把源码放到自已PHP服务器上。
<?php/** * FOFA 资产抓取、多模式自动路径映射与地址替换工具 (移动端适配版) */header('Content-Type: text/html; charset=utf-8');set_time_limit(300); $all_data = []; $message = '';// 1. 定义关键字与路径的映射关系$path_configs = [    'ZHGXTV' => '/ZHGXTV/Public/json/live_interface.txt',    'iptv/live/zh_cn.js' => '/iptv/live/1000.json?key=txiptv',];$query_type = $_POST['query_type'] ?? 'ZHGXTV';$custom_query = trim($_POST['custom_query'] ?? '');$province = trim($_POST['province'] ?? '');$cookie = trim($_POST['cookie'] ?? '');$final_query = ($query_type === 'custom') ? $custom_query : $query_type;$provinces_list = ["北京""天津""河北""山西""内蒙古""辽宁""吉林""黑龙江""上海""江苏""浙江""安徽""福建""江西""山东""河南""湖北""湖南""广东""广西""海南""重庆""四川""贵州""云南""西藏""陕西""甘肃""青海""宁夏""新疆""台湾""香港""澳门"];/** * 智能并发抓取函数 */function fetch_iptv_multi_smart($ip_ports$query_key$path_configs$batch_size = 40) {    $all_results = [];    $chunks = array_chunk($ip_ports$batch_size);     // 获取匹配路径,默认 fallback 到常见 json 路径    $target_path = $path_configs[$query_key] ?? '/iptv/live/1000.json?key=txiptv';    foreach ($chunks as $batch) {        $mh = curl_multi_init();        $ch_map = [];         foreach ($batch as $ip_port) {            $target_url = "http://{$ip_port}" . $target_path;            $ch = curl_init($target_url);            curl_setopt_array($ch, [                CURLOPT_RETURNTRANSFER => true,                CURLOPT_TIMEOUT => 7,                           CURLOPT_CONNECTTIMEOUT => 4,                    CURLOPT_SSL_VERIFYPEER => false,                CURLOPT_USERAGENT => "Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15",            ]);            curl_multi_add_handle($mh$ch);            $ch_map[(int)$ch] = ['handle' => $ch'ip' => $ip_port];        }        $active = null;        do { $mrc = curl_multi_exec($mh$active); } while ($mrc == CURLM_CALL_MULTI_PERFORM);        while ($active && $mrc == CURLM_OK) {            if (curl_multi_select($mh) != -1) {                do { $mrc = curl_multi_exec($mh$active); } while ($mrc == CURLM_CALL_MULTI_PERFORM);            }        }        foreach ($ch_map as $item) {            $ch = $item['handle'];            $res = curl_multi_getcontent($ch);            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);            $current_ip = $item['ip'];             if ($code === 200 && !empty($res)) {                $temp_channels = [];                $is_json = (strpos($res'{') !== false || strpos($res'[') !== false);                if (!$is_json) {                    // 处理 TXT 格式 (如 ZHGXTV)                    $lines = explode("\n", str_replace("\r"""$res));                    foreach ($lines as $line) {                        if (strpos($line',http') !== false) {                            $fixed_line = preg_replace('/http:\/\/[^\/]+\//'"http://{$current_ip}/"$line);                            $temp_channels[] = trim($fixed_line);                        }                    }                } else {                    // 处理 JSON 格式                    $json = json_decode($restrue);                    $list = $json['data'] ?? (is_array($json) ? $json : []);                    foreach ($list as $v) {                        if (isset($v['name'], $v['url'])) {                            $raw_url = $v['url'];                            if (strpos($raw_url'http') === 0) {                                $fixed_url = preg_replace('/http:\/\/[^\/]+\//'"http://{$current_ip}/"$raw_url);                            } else {                                $fixed_url = "http://{$current_ip}" . (strpos($raw_url'/') === 0 ? '' : '/') . $raw_url;                            }                            $temp_channels[] = "{$v['name']},{$fixed_url}";                        }                    }                }                if (!empty($temp_channels)) $all_results[$current_ip] = $temp_channels;            }            curl_multi_remove_handle($mh$ch);            curl_close($ch);        }        curl_multi_close($mh);    }    return $all_results;}// 处理 FOFA 请求if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($cookie)) {    $fofa_syntax = $final_query;    if (!empty($province)) $fofa_syntax .= ' && region="' . $province . '"';    $qbase64 = base64_encode($fofa_syntax);    $url = "https://fofa.info/result?qbase64=" . $qbase64;    $ch = curl_init($url);    curl_setopt_array($ch, [        CURLOPT_RETURNTRANSFER => true,        CURLOPT_SSL_VERIFYPEER => false,        CURLOPT_HTTPHEADER => ["Cookie: " . $cookie],        CURLOPT_USERAGENT => "Mozilla/5.0",    ]);    $html = curl_exec($ch);    curl_close($ch);    if ($html) {        preg_match_all('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+/'$html$matches);        if (!empty($matches[0])) {            $raw_ips = array_unique($matches[0]);            $all_data = fetch_iptv_multi_smart($raw_ips$query_type$path_configs, 30);            if (!empty($all_data)) {                $file_content = "";                foreach ($all_data as $ips$file_content .= implode("\n"$ips) . "\n";                file_put_contents('fofa_results.txt'$file_content);                $message = "<b style='color:green;'>成功抓取 " . count($all_data) . " 个有效节点</b>";            } else {                $message = "<b style='color:red;'>未探测到有效直播源</b>";            }        }    }}?><!DOCTYPE html><html lang="zh-CN"><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">    <title>FOFA酒店源探测器</title>    <style>        * { box-sizing: border-box; }        body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f0f2f5; margin: 0; padding: 10px; color: #333; }        .card { max-width: 800px; margin: 0 auto; background: #fff; padding: 15px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }        h2 { text-align: center; font-size: 1.2rem; color: #1a73e8; margin-bottom: 20px; }        .form-group { margin-bottom: 15px; }        label { display: block; margin-bottom: 5px; font-weight: bold; font-size: 0.9rem; }        /* 响应式栅格系统 */        .grid-row { display: flex; flex-wrap: wrap; gap: 10px; }        .grid-col { flex: 1; min-width: 140px; }        select, input, textarea {             width: 100%;             padding: 12px;             border: 1px solid #ddd;             border-radius: 8px;             font-size: 16px; /* 防止 iOS 自动放大屏幕 */            background: #fafafa;        }        textarea { height: 100px; font-family: monospace; }        .btn {             background: #1a73e8;             color: white;             border: none;             padding: 15px;             width: 100%;             border-radius: 8px;             cursor: pointer;             font-weight: bold;             font-size: 1rem;            margin-top: 10px;        }        .btn:active { background: #1557b0; }        /* 结果展示区适配 */        .result-item { margin-top: 15px; border: 1px solid #eee; border-radius: 8px; background: #fff; overflow: hidden; }        .res-header {             background: #f8f9fa;             padding: 10px;             font-size: 0.85rem;             font-weight: bold;             border-bottom: 1px solid #eee;             display: flex;             justify-content: space-between;        }        .res-body {             background: #202124;             color: #8ab4f8;             padding: 10px;             font-family: 'Courier New', monospace;             font-size: 0.8rem;             max-height: 150px;             overflow-y: auto;             white-space: pre-wrap;             word-break: break-all;        }        .status-msg { text-align: center; margin: 15px 0; font-size: 0.9rem; }    </style></head><body><div class="card">    <h2>📡 FOFA酒店源探测器</h2>    <form method="POST">        <div class="grid-row form-group">            <div class="grid-col">                <label>查询关键字</label>                <select name="query_type" onchange="toggleCustom(this.value)">                    <option value="ZHGXTV" <?= $query_type=='ZHGXTV'?'selected':'' ?>>ZHGXTV</option>                    <option value="iptv/live/zh_cn.js" <?= $query_type=='iptv/live/zh_cn.js'?'selected':'' ?>>iptv/live/zh_cn.js</option>                </select>            </div>            <div class="grid-col">                <label>选择省份</label>                <select name="province">                    <option value="">全国</option>                    <?php foreach($provinces_list as $p): ?>                    <option value="<?=$p?>" <?=$province==$p?'selected':''?>><?=$p?></option>                    <?php endforeach; ?>                </select>            </div>        </div>        <div id="custom-field" class="form-group" style="display: <?= $query_type=='custom'?'block':'none' ?>;">            <label>自定义查询语句</label>            <input type="text" name="custom_query" value="<?=htmlspecialchars($custom_query)?>" placeholder="例如: app='IPTV'">        </div>        <div class="form-group">            <label>FOFA Cookie</label>            <textarea name="cookie" required placeholder="请从浏览器开发者工具复制 Cookie 到此..."><?= htmlspecialchars($cookie) ?></textarea>        </div>        <button type="submit" class="btn">⚡ 立即开始并发探测</button>    </form>    <?php if($message): ?>        <div class="status-msg"><?= $message ?></div>    <?php endif; ?>    <?php foreach ($all_data as $ip => $channels): ?>        <div class="result-item">            <div class="res-header">                <span>📍 <?= htmlspecialchars($ip) ?></span>                <span style="color:#34a853;"><?= count($channels) ?> 频道</span>            </div>            <div class="res-body"><?php foreach($channels as $lineecho htmlspecialchars($line) . "\n"; ?></div>        </div>    <?php endforeach; ?></div><script>function toggleCustom(val) {    document.getElementById('custom-field').style.display = (val === 'custom') ? 'block' : 'none';}</script></body></html>