Skip to content

Commit

Permalink
Add local replayer
Browse files Browse the repository at this point in the history
  • Loading branch information
leohearts committed Sep 16, 2020
1 parent 96a2992 commit fe1e654
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions watchbird.php
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,17 @@ function changetheme() {
document.cookie = "theme=light";
}
}
async function checkLocalReplayerAvailablility(){
await fetch(document.getElementById("replayer_addr").value + "?watchbird=checkExistence")
.then(function(Response) {
return Response.text()
})
.then(function(txt) {
if (txt == "I'm still alive"){
document.getElementById("use_custom_replayer").checked = true;
}
})
}
document.addEventListener("DOMContentLoaded",function () {
if (document.cookie.replace(/(?:(?:^|.*;\s*)theme\s*\=\s*([^;]*).*$)|^.*$/, "$1") == "dark"){
changetheme();
Expand All @@ -866,6 +877,9 @@ function changetheme() {
}
if (document.cookie.replace(/(?:(?:^|.*;\s*)flag_regex\s*\=\s*([^;]*).*$)|^.*$/, "$1") != ""){
document.getElementById("flag_regex").value = unescape(document.cookie.replace(/(?:(?:^|.*;\s*)flag_regex\s*\=\s*([^;]*).*$)|^.*$/, "$1"));
}
if (document.cookie.replace(/(?:(?:^|.*;\s*)replayer_addr\s*\=\s*([^;]*).*$)|^.*$/, "$1") != ""){
document.getElementById("replayer_addr").value = unescape(document.cookie.replace(/(?:(?:^|.*;\s*)replayer_addr\s*\=\s*([^;]*).*$)|^.*$/, "$1"));
}
startDaemon();
startKillallTimer();
Expand All @@ -876,6 +890,7 @@ function changetheme() {
console.log('用户拒绝通知');
}
});
checkLocalReplayerAvailablility();
});
async function startKillallTimer(){
document.getElementById("config_scheduled_killall").nextElementSibling.nextSibling.textContent = "每分钟自动关闭所有Web进程并清理Crontab";
Expand Down Expand Up @@ -1028,7 +1043,11 @@ function handle_replay(){
packet = packet.replace(new RegExp('host: {0,}[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}', 'i'), 'Host: '+ip+":"+port);
}
}
await fetch("?watchbird=replay&ip="+ip+"&port="+port, {
var FinalFetchUrl = "?watchbird=replay&ip="+ip+"&port="+port;
if (document.getElementById("use_custom_replayer").checked){
FinalFetchUrl = document.getElementById("replayer_addr").value + FinalFetchUrl;
}
await fetch(FinalFetchUrl, {
body: packet,
method: 'POST',
}).then(function(response) {
Expand Down Expand Up @@ -1128,6 +1147,7 @@ function handle_replay(){
document.cookie = "submit_packet_header="+escape(document.getElementById("submit_packet_header").value);
document.cookie = "submit_packet_body="+escape(document.getElementById("submit_packet_body").value);
document.cookie = "flag_regex="+escape(document.getElementById("flag_regex").value);
document.cookie = "replayer_addr=" + escape(document.getElementById("replayer_addr").value);
var domInputNodes = document.getElementsByClassName("dest-selector-multi");
var ip_part1_start = domInputNodes[0].querySelectorAll("input")[0].value - 0;
var ip_part1_end = domInputNodes[0].querySelectorAll("input")[1].value - 0;
Expand Down Expand Up @@ -1405,9 +1425,9 @@ class="mdui-icon material-icons">save</i></button></div>');
<div id="repeater" class="mdui-dialog repeater" style="transition: all .15s linear 0s;">
<div class="mdui-dialog-content mdui-col" style="scrollbar-width: none;">
<div class="mdui-dialog-title mdui-row" style="display: flex;">
<div class="mdui-col-xs-4">重放</div>
<div class="mdui-col-xs-6 mdui-row" style="height: 10px;">
<label class="mdui-col-xs-4 mdui-checkbox">
<div class="mdui-col-xs-2">重放</div>
<div class="mdui-col-xs-8 mdui-row" style="height: 10px;">
<label class="mdui-col-xs-3 mdui-checkbox">
<input id="modifyHost" type="checkbox" checked/>
<i class="mdui-checkbox-icon"></i>
<small style="margin-left: 15px;" class="mdui-textfield-label">修改Host</small>
Expand All @@ -1417,10 +1437,19 @@ class="mdui-icon material-icons">save</i></button></div>');
<input id="passhost" type="checkbox" checked/>
<i class="mdui-checkbox-icon"></i>
</label>
<div class="mdui-col-xs-6 mdui-textfield" style="padding: 0;margin-top: -10px;">
<div class="mdui-col-xs-3 mdui-textfield" style="padding: 0;margin-top: -10px;">
<label class="mdui-textfield-label">跳过该Host</label>
<input id="myhost" class="mdui-textfield-input" type="text" style="height: 30px;" />
</div>
<label class="mdui-col-xs-1 mdui-checkbox" style="right:-10px">
<input id="use_custom_replayer" type="checkbox"/>
<i class="mdui-checkbox-icon"></i>
</label>
<div class="mdui-col-xs-4 mdui-textfield" style="padding: 0;margin-top: -10px;" title="使用存在本地web服务器的watchbird发包, 应对靶机间不能互联的情况. 使用方法: 将watchbird.php放在本地服务器的根目录, 或一个任意目录, 然后修改本地发包器的值. 本选项默认关闭, 将在检测到本地发包器存在时自动开启.">
<label class="mdui-textfield-label">本地发包器</label>
<input id="replayer_addr" class="mdui-textfield-input" type="text" style="height: 30px;" value="http://127.0.0.1/watchbird.php"/>
</div>
</div>
<button onclick="replaypacket();" class="mdui-btn mdui-btn-raised mdui-ripple mdui-col-xs-1 mdui-color-theme-accent">Go!</button>
</div>
Expand Down Expand Up @@ -1839,7 +1868,7 @@ function uninstall($dir)
if ($_GET['watchbird'] === 'replay'){
ob_end_clean();
session_start();
if ($_SESSION['login'] !== 'success') {
if ($_SESSION['login'] !== 'success' && $_SERVER['REMOTE_ADDR'] !== '127.0.0.1') {
die('Credential error');
}
set_time_limit(3);
Expand All @@ -1864,6 +1893,9 @@ function uninstall($dir)
// socket_close($socket);
die();
}
if ($_GET['watchbird'] === 'checkExistence'){
die("I'm still alive");
}
if ($_GET['watchbird'] === 'scheduled_killall'){
ob_end_clean();
session_start();
Expand Down

0 comments on commit fe1e654

Please sign in to comment.