Daily Shaarli

All links of one day in a single page.

March 29, 2014

Show what PID is listening on port 80 on Linux | commandlinefu.com

lsof -nPi tcp:80

Draw kernel module dependancy graph. | commandlinefu.com

lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@=split/\s+/; print "\"$[0]\" -> \"$\"\n" for split/,/,$[3]}print "}"' | dot -Tpng | display -

Delete all files in a folder that don't match a certain file extension | commandlinefu.com

command !(regexp to remove from matching)

Note: This is a feature of bash, and it only works if you've enabled 'extglob' (Extended Pattern Matching):
shopt -s extglob

output your microphone to a remote computer's speaker | commandlinefu.com

arecord -f cd | ssh -C user@host aplay -f cd

or the other way around

ssh -C user@host arecord -f cd | aplay -f cd

How to: Shellcode to reverse bind a shell with netcat

There are several ways to obtain access to a local shell with a remote connection. The most common of all is to open a known port with a tcp socket and bind its stdout/stderr/stdin to a newly forked shell. This way we can connect from our computer with a simple netcat command. However, this doesn’t work well most of the time: most of the public-facing servers out there have only a few number of ports open to the outside world (like http(s), ftp, smtp, etc) and the remaining inbound requests are usually filtered and dropped by iptables or firewalls.

The solution to this is to use a reverse bind for your local shell. A reverse bind is a simple operation that turns the client into a server and vice-versa. Originally, you’d have opened a port on the target and waited for inbound connections (from your attacking machine). Reverse this and you’ll have an open connection on your own machine waiting for the target machine to connect, this turns the attacker into the receiver waiting for some poor victim to fall into the trap.

grep -v with multiple patterns. | commandlinefu.com

sed '/test/{/error|critical|warning/d}' somefile

prevent large files from being cached in memory (backups!) | commandlinefu.com

nocache <I/O-heavy-command>

A fun thing to do with ram is actually open it up and take a peek. This command will show you all the string (plain text) values in ram | commandlinefu.com

strings /dev/mem|less

Close shell keeping all subprocess running | commandlinefu.com

disown -a && exit

All commands | commandlinefu.com

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Binary to shellcode c string

for i in $(objdump -d binary.o -M intel |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo

Copy an element from the previous command | commandlinefu.com

!:1-3

move you up one directory quickly | commandlinefu.com

shopt -s autocd

intercept stdout/stderr of another process | commandlinefu.com

strace -e write=1,2 -p $PID 2>&1 | sed -un "/^ |/p" | sed -ue "s/^.{9}(.{50}).+/\1/g" -e 's/ //g' | xxd -r -p

save command output to image | commandlinefu.com

ifconfig | convert label:@- ip.png

Rapidly invoke an editor to write a long, complex, or tricky command | commandlinefu.com

ctrl-x e

Next time you are using your shell, try typing ctrl-x e (that is holding control key press x and then e). The shell will take what you've written on the command line thus far and paste it into the editor specified by $EDITOR. Then you can edit at leisure using all the powerful macros and commands of vi, emacs, nano, or whatever.