request specific port

This commit is contained in:
2019-07-27 20:16:57 +03:00
parent bb89778b62
commit 022a53904c
2 changed files with 18 additions and 8 deletions

View File

@@ -85,6 +85,14 @@ def setup_options():
type = str,
help="Id name for backdoor"
)
parser_open.add_argument(
action = 'store',
dest = 'port',
type = int,
default = None,
nargs = '?',
help="Request a port for backdoor"
)
parser_wait = subparsers.add_parser(
"keep",
@@ -206,11 +214,12 @@ class DataBase:
self.conn_end()
def update(self, id):
def update(self, id, port = None):
self.id = id
port = self.get_port(id)
if port == None:
port = self.new_port()
port = self.get_port(id)
if port == None:
port = self.new_port()
parent = self.get_pid()
self.db = self.conn.cursor()
self.db.execute("INSERT OR REPLACE INTO ports(id,port,date,pid,host,die) \
@@ -333,7 +342,7 @@ if __name__ == "__main__":
db.connect_backdoor(opts.id)
if opts.command == "open":
print(db.update(opts.id))
print(db.update(opts.id, opts.port))
if opts.command == "keep":
print(db.update(opts.id))

View File

@@ -13,6 +13,7 @@ if [[ "$1" = update ]]; then
fi
_ssh() {
trap 'kill -INT -$sshpid; exit;' INT
timeout -k 10 3700 ssh \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
@@ -21,15 +22,16 @@ _ssh() {
-o ServerAliveCountMax=3 \
-p ${BACKDOORPORT} \
${BACKDOORHOST} \
"$@"
"$@" &
sshpid=$!
wait $sshpid
#~ -o "ExitOnForwardFailure yes" \
}
BACKDOORHOST={{BACKDOORHOST}}
BACKDOORPORT={{BACKDOORPORT}}
USER=$( id -u -n )
echo use of ssh-add is encouraged
( sleep 3; printf "%d\r" $SECONDS ) &
echo "Must use ssh agent (ssh-add)"
while true; do
port=$( _ssh bin/ssh-backdoor open $USER@$HOSTNAME )
[[ -z "$port" ]] && { sleep 2; continue; }
@@ -47,4 +49,3 @@ while true; do
printf " $i\r"
done
done
kill %1