bolus Posted June 20, 2018 Share Posted June 20, 2018 I'm trying a proof of concept whereby when my Pi starts, it kicks off a Netcat session with my Kali laptop. Setup: Kali laptop (192.168.1.215): netcat -lvp 443 Pi (192.168.1.217): I have the script boot_netcat.sh (and ran chmod +x on it): !#/bin/bash netcat 192.168.1.215 443 -w 10 In crontab I have added: @reboot /home/pi/scripts/boot_netcat.sh When I reboot the Pi, the script isn't run. I've tried adding sudo to the script and also the crontab entry - still no joy. I've also tried this by ensuring cron is run at boot via /etc/rc.local: /etc/init.d/cron/start And still nothing. If I run ps aux |grep cron I can see cron running. If I run the script on its own, it executes and connects to my Kali laptop netcat listener. I'm sure it's something very simple that I'm not doing or not seeing - any suggestions as to what the problem is, or is there a better way to do this? Thanks in advance Quote Link to comment Share on other sites More sharing options...
i8igmac Posted June 20, 2018 Share Posted June 20, 2018 place your netcat command in rc.local Or are you trying to explore new methods? Like schedule tasks Quote Link to comment Share on other sites More sharing options...
bolus Posted June 21, 2018 Author Share Posted June 21, 2018 Thanks for the quick suggestion @i8igmac - appreciate it. Unfortunately, that's not worked. I've edited /etc/rc.local and added netcat 192.168.1.215 443 -w 10 On reboot - nothing. If I run the command stand alone, it connects fine, so I've ruled out a connectivity issue there. Could it be anything to do with the user that the pi boots with? I've tried adding sudo in front of the netcat command - nothing. any suggestions from you guys is appreciated Quote Link to comment Share on other sites More sharing options...
i8igmac Posted June 21, 2018 Share Posted June 21, 2018 i have experience this same thing. I believe netcat starts up before your networking services completely configured. What worked for me. Sleep 15 netcat . . . 192. Exit 0 1 Quote Link to comment Share on other sites More sharing options...
PoSHMagiC0de Posted June 22, 2018 Share Posted June 22, 2018 Hmm, could the command be added to the interfaces file after autoup-ing the interface? Might can create a service that starts after the interface is up. Background bash file called from local.rc that looks at interface every 5 seconds and launches netcat when an ip shows? 1 Quote Link to comment Share on other sites More sharing options...
i8igmac Posted June 22, 2018 Share Posted June 22, 2018 20 hours ago, bolus said: Thanks for the quick suggestion @i8igmac - appreciate it. Unfortunately, that's not worked. I've edited /etc/rc.local and added netcat 192.168.1.215 443 -w 10 On reboot - nothing. If I run the command stand alone, it connects fine, so I've ruled out a connectivity issue there. Could it be anything to do with the user that the pi boots with? I've tried adding sudo in front of the netcat command - nothing. any suggestions from you guys is appreciated I hope you try what I suggested above to confirm what I suspect is happening. You should also try this. pipe the netcat data to a file to see if there is a error logged. With out the 'sleep 15' netcat 192.168.69.1 -w 10 > /tmp/nc.log exit 0 1 Quote Link to comment Share on other sites More sharing options...
bolus Posted June 23, 2018 Author Share Posted June 23, 2018 On 6/21/2018 at 11:12 PM, i8igmac said: i have experience this same thing. I believe netcat starts up before your networking services completely configured. What worked for me. Sleep 15 netcat . . . 192. Exit 0 @i8igmac- you've cracked it! Added the sleep command and it's working a treat now. thank you for your assistance and suggestions, really appreciate it Quote Link to comment Share on other sites More sharing options...
i8igmac Posted June 23, 2018 Share Posted June 23, 2018 1 hour ago, bolus said: @i8igmac- you've cracked it! Added the sleep command and it's working a treat now. thank you for your assistance and suggestions, really appreciate it I have experience this same thing. When I made my reaver drop box. I think its the lack of cpu power, the time it takes to start up all the services is extremely slow. If netcat launches before your wlan is Up and configured then netcat will pop a error 'device not up' Glad it worked for you. 1 Quote Link to comment Share on other sites More sharing options...
i8igmac Posted June 23, 2018 Share Posted June 23, 2018 netcat.rb While true system("nc 192.168.69.50 -w 10") sleep 5 end You can make netcat retry every 5 seconds with a ruby script like above. Or bash/perl/python. If netcat session breaks or drops this will be persistent. rc.local sleep 15 ruby /home/projects/netcat.rb & Exit 0 Quote Link to comment Share on other sites More sharing options...
jOte- Posted June 30, 2018 Share Posted June 30, 2018 (edited) no @reboot ... in cronjobs.... I think this is a good example for this "problem"... Add a cronjob in script croncmd="/home/yourusername/ssh.vpn.start" cronjob="*/5 * * * * $croncmd" ( crontab -l | grep -v -F "$croncmd"; echo "$cronjob" ) | crontab - Delete a cronjob in script croncmd="/home/yourusername/ssh.vpn.start" cronjob="*/5 * * * * $croncmd" ( crontab -l | grep -v -F "$croncmd" ) | crontab - I use this script to be sure it is connected.... ssh.vpn.start #!/bin/bash up=`ping -c1 192.168.0.6 &> /dev/null; echo $?` if [ "$up" -eq "1" ] then ssh -NTCf -w 0:0 -o TCPKeepAlive=yes -o ServerAliveInterval=60 root@hostname tun=`ip a show tun0 &> /dev/null ; echo $?` if [ "$tun" -eq "0" ] then ip link set tun0 up ip addr add 10.0.0.174/32 peer 10.0.0.184 dev tun0 ip route add 192.168.0.0/24 via 10.0.0.184 arp -sD 10.0.0.184 eth0 pub echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward croncmd="/home/yourusername/ssh.vpn.start" cronjob="*/5 * * * * $croncmd" ( crontab -l | grep -v -F "$croncmd"; echo "$cronjob" ) | crontab - ssh root@hostname 'ip link set tun0 up && ip addr add 10.0.0.184/32 peer 10.0.0.174 dev tun0 && ip route add 10.0.0.0/24 via 10.0.0.174' fi fi ssh.vpn.stop #!/bin/bash sudo kill $(ps aux | grep 'ssh -NTCf -w 0:0' | awk '{print $2}') ps aux | grep 'ssh -NTCf -w 0:0' croncmd="/home/yourusername/ssh.vpn.start" cronjob="*/5 * * * * $croncmd" ( crontab -l | grep -v -F "$croncmd" ) | crontab - https://wiki.archlinux.org/index.php/VPN_over_SSH https://help.ubuntu.com/community/SSH_VPN +---------------+ OpenSSH 4.3 +---------------+ | Machine A | tun0 -- Tunnel Interface -- tun0 | Machine B | | Has a tunnel | <------------------------------->| Has a tunnel | | and ethernet | 10.0.0.100 10.0.0.200 | and ethernet | +-------+-------+ point to point connection +-------+-------+ eth0 | creates a bridge | eth0 10.0.0.100 | that plugs machine B | 192.168.0.100 port 22 | into network A | forwarded | | here | | +-------+-------+ +-~-~-~-~-~-~-~-+ +-------+-------+ | Network A | | | | Network B | | 10.0.0.1/24 | 1.2.3.4 | The Internet | | 192.168.0.1/24| | Has internet |<-------->| |<----->| Has internet | | NAT gateway | Routable | | | NAT gateway | +---------------+ Address +-~-~-~-~-~-~-~-+ +---------------+ VLAN ALL UNTRUSTED DEVICES!!! THEY ALL PHONE HOME.... Edited June 30, 2018 by jOte- Quote Link to comment Share on other sites More sharing options...
vailixi Posted September 2, 2018 Share Posted September 2, 2018 On 7/25/2018 at 5:03 PM, kdodge said: I believe that systemd is used in kali: you might be able to run it as a service like this On 7/25/2018 at 5:03 PM, kdodge said: I believe that systemd is used in kali: you might be able to run it as a service like this $ cat /lib/systemd/system/netcat.service [Unit] Description=Run a netcat session After=network.target [Service] Type=simple User=kaliuser WorkingDirectory=/home/kaliuser ExecStart=/bin/netcat 192.168.1.215 443 -w 10 Restart=on-failure [Install] WantedBy=multi-user.target $ sudo systemctl enable netcat.service You'll probably want to reload the systemd daemon. systemctl daemon-reload before systemctl enable netcat systemctl start netcat 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.