I have one http server open 8000 port like next:
orange#orange:~$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
As known to all, there are several versions netcat, but for some reasons, I can just use next versions:
root#orange:~# busybox nc
BusyBox v1.27.2 (Ubuntu 1:1.27.2-2ubuntu3.2) multi-call binary.
Usage: nc [-iN] [-wN] [-l] [-p PORT] [-f FILE|IPADDR PORT] [-e PROG]
Open a pipe to IP:PORT or FILE
-l Listen mode, for inbound connects
(use -ll with -e for persistent server)
-p PORT Local port
-w SEC Connect timeout
-i SEC Delay interval for lines sent
-f FILE Use file (ala /dev/ttyS0) instead of network
-e PROG Run PROG after connect
This means only above parameters should be used.
I did next:
root#orange:~# rm -f /tmp/backpipe && mkfifo /tmp/backpipe && cat /tmp/backpipe | busybox nc 127.0.0.1 8000 | busybox nc -l -p 80 > /tmp/backpipe
The aim is: when user visit http://127.0.0.1:80, it will automactically forward to http://127.0.0.1:8000, so the contents of python simplehttpserver will returned to user.
Finally, I launch test client:
orange#orange:~$ wget http://127.0.0.1
--2019-06-26 22:47:25-- http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1378 (1.3K) [text/html]
Saving to: ‘index.html’
index.html 100%
[==============================================>] 1.35K --.-KB/s in 0s
2019-06-26 22:47:25 (505 MB/s) - ‘index.html’ saved [1378/1378]
Above all ok, but back to the port forward command, I found it had been exit, so it nolonger receive the second time connect.
So, my question is, with above busybox netcat, how can I make this port forward command not exit after the first connection.
NOTE: I don't want the solution with for-loop, I just want to find the way to do port forward with above netcat, meanwhile it will continue serve after the first connection.
You may have been using an older version of busybox. Current versions come with the -lk flag, which allows you to persist the server beyond just a single connection.
In order to accomplish what you wanted, you can do something like this:
busybox nc -lk -p 80 -e busybox nc localhost 8000
Related
I have a problem about connections to a docker containers from outside of my network. Iptables not worked yet for me (See this question).
The container open a connection on port 9010 which maps to its 443:
docker run -d [some other configs] --restart=always -p 9010:443 -p 9010:443/udp xxx/myImage
and I cannot see the client connections to this in my host:
root#ubuntu:~# netstat -anlp | grep ESTABLISHED
tcp 0 64 88.99.126.173:22 191.96.180.79:2543 ESTABLISHED 20855/sshd: root#pt
However I can see it inside container:
root#ubuntu:~# docker exec -it b7772c4d43dc /bin/bash -c 'netstat -anlp | grep ESTABLISHED'
tcp 0 0 ::ffff:172.17.0.2:443 ::ffff:191.96.180.79:3298 ESTABLISHED 7/python
Now I want to close this connection in that container, but since docker is from python:3.6-alpine image, there is not useful commands such as tcpkill command. How I can close this connections by bash inside my host.
I would like to use snmp to monitor my localhost and have installed the corresponding package on Ubuntu 18.03 with apt install snmp. Without having changed the default configuration, I have launched the daemon with systemctl start snmpd. After launching the daemon the output of lsof -i -n | grep snmpd is as follows:
snmpd 14668 Debian-snmp 12u IPv4 13252990 0t0 UDP 127.0.0.1:snmp
snmpd 14668 Debian-snmp 13u IPv4 13252988 0t0 UDP *:41898
I am wondering about the second line of the output as the port has been opened to the outside. Restarting the daemon changes the open port to another (randomized?) high port number. I have been looking up this behaviour a couple of hours and wasn´t able to find any explanation.
Can anybody explain to me whats going on here or how to disable/remove the open port?
Configuration
AgentAdress is configured as follows:
# /etc/snmp/snmpd.conf
# Listen for connections from the local system only
agentAddress udp:127.0.0.1:161
The daemon has been launched with following options:
# /etc/default/snmp
# snmpd options (use syslog, close stdin/out/err).
SNMPDOPTS='-Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid'
Output of ps aux | grep snmpd
/usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux mteTrigger mteTriggerConf -f
So, if anybody comes across the same question: The UDP port has been opened by snmp-traps. In order to avoid this behavior, I had to comment out following line in the snmpd.conf:
/etc/snmp/snmpd.conf
# ACTIVE MONITORING
# send SNMPv1 traps
# !comment this line out!
# trapsink localhost public
Read this link for further information: https://sourceforge.net/p/net-snmp/mailman/message/29219475/
i have to start an Ncat server in UDP mode listening to port 1337 on one terminal
Then on the other terminal with ONE command Nping, i have to send 2 UDP packets saying the message : Reseaux_pour_ingenieurs_
For my first terminal i did : ncat -l -p 1337 -u
For my second terminal i tried :
nping -c 2 --data-string "Reseaux_pour_ingenieurs_" --udp -p 1337
console answer : WARNING: No targets were specified, so 0 hosts pinged.
i also tried : nping -c 2 --udp -p 1337
console : WARNING: No targets were specified, so 0 hosts pinged.
So i'm kinda lost on how to do this how do i send this while using only one nping command ?
Thank you very much !
you didn't specify the ip for your target
Try this :
nping --udp -c 2 --data-string "Reseaux_pour_ingenieurs_" -p 1337 127.0.0.1
I'm having a TCP-Server which prints out some logging information. Normally I'm used to dump these logging to terminal by:
nc -v 192.168.0.42 7777
Or I dump the logging to a file using
nc -v 192.168.0.42 7777 >> log.log
Well, sometimes the server runs through a reboot. Thus the connection to the client is disconnected and the logging to the file log.log stops.
So I ask: How to reconnect automatically to the TCP Server?
I tried this:
while true; do nc -v 192.168.0.42 7777; done
But this does not work. If the server does its reboot nc does not notice that the connection has become inactive.
If you would like to reproduce this scenario just open a server-terminal with nc -l 7777 and then run the commands above within a second terminal. The server can then be terminated by ctrl-c.
I want to setup a simple ssh tunnel from a local machine to a machine on the internet.
I'm using
ssh -D 8080 -f -C -q -N -p 12122 <username>#<hostname>
Setup works fine (I think) cause ssh returs asking for the credentials, which I provide.
Then i do
export http_proxy=http://localhost:8080
and
wget http://www.google.com
Wget returns that the request has been sent to the proxy, but no data is received back.
What i need is a way to look at how ssh is processing the request....
To get more information out of your SSH connection for debugging, leave out the -q and -f options, and include -vvv:
ssh -D 8080 -vvv -N -p 12122 <username>#<hostname>
To address your actual problem, by using ssh -D you're essentially setting up a SOCKS proxy which I believe is not supported by default in wget.
You might have better luck with curl which provides SOCKS suport via the --socks option.
If you really really need to use wget, you'll have to recompile your own version to include socks support. There should be an option for ./configure somewhere along the lines of --with-socks.
Alternatively, look into tsock which can intercept outgoing network connections and redirecting them through a SOCKS server.