Netstat without netstat
staaldraad.github.io
staaldraad.github.io
If you have the ability to write anywhere to disk (e.g., even /tmp, /run), dropping a copy of Busybox (a statically linked, minimal clone of many of the base tools like ifconfig, netstat) has helped me more than once.
(I didn't have a working scp on a machine, and it was the ssh "gateway" to another machine that I needed access to. To jump to the next machine, I needed to run either ssh or nc, both of which were defunct (the HDD was dying). Copied busybox over for nc, and it worked like a charm. I had to write a small python script to transform the binary into a printf command to write it out to disk, as essentially nothing but bash builtins worked due to the condition of the disk. Had a minor panic attack when I realized I needed to chmod +x it, but chmod still worked. In hindsight, I think I could have set the umask prior to the printf to avoid that step.)
If only Bash worked then you can use Bash's builtin TCP/IP stack[1][2] to transfer data (inc files)[1][2]
[1] http://www.linuxjournal.com/content/tech-tip-tcpip-access-us...
[2] http://www.linuxjournal.com/content/more-using-bashs-built-d...
This is how I got around a similar problem as yourself regarding needing to get a file on a system which was severely locked down.
Also you can get around the `chmod +x` problem by calling ld directly[3]
Why not create a tmpfs directory over some existing directory? Why try to write to disk when the disk is known to be malfunctioning? Then send the static binaries needed to the tmpfs directory, e.g., using netcat. Perhaps I have misunderstood the problem.
Many years ago, I once tried a pre-packaged, well-regarded, "system rescue live CD". When I tried to use it on a computer with a malfunctioning disk, the rescue CD would fail to boot. Apparently it tried to access the computers HDD during boot. I switched to using another less-hyped OS to boot from USB stick into RAM and encountered no problems rescuing the malfunctiong HDD. Oh well.
Why try to use use the disk if it is not working?
Bonus: aligned columns[1]
(tested on 80x25 and only with text from blog, not actual /proc/net/tcp)
[1] Hack. Probably there is a better way to do alignment using only printf; alas I only know a subset of printf features.
#! /bin/sh
printf '%s\t\t\t%s\n' Local Remote
sed '
/: /!d;
s/.*: //;
s/ /-/;
s/ .*//;
s/[0-9A-F][0-9A-F]/0x& /g;
s/ 0x//4;
s/ 0x//7;
s/://g;
s/-//;
' /proc/net/tcp \
|while read a b c d e g h i j k;do
s=$(printf '%d.%d.%d.%d:%d %d.%d.%d.%d:%-22d\n' \
$d $c $b $a $e $j $i $h $g $k);
l=${s%% *};r=${s#* };
if test ${#s} -lt 45;then
printf '%s\t\t%s\n' $l $r;else
printf '%s\t%s\n' $l $r;fi;
doneGood info, though. Lots of info to bad had in /proc but needs parsing.
So, yes, maybe they know better.
Reading this article is like reading about elite navy seals who storm an enemy outpost, get inside, and then get distracted trying to refashion a stapler they find laying around into a lock-picking device to open the safe.
If someone is actually working for an intelligence agency/criminal organization, or is part of an internal red team, then they have the time and resources to target specific classes of system, plan everything out, and build a package that will do exactly what they want against those specific systems, without any operator interaction.
Most pen testers don't have the time to do that, let alone do it well, and there's a good chance that anything automated that they hack together will miss something interesting either because the person who built the payload didn't expect it, or because blindly doing all of the things that would locate interesting information would involve sending gigs of data back to C2.
Knowing how to quickly improvise things like what's described in the article is super-helpful for the more generalized "see how you can misuse this system" type of pen testing.
Can you clarify this? I'm not really sure what it means.
I've also had to deal with a lot of this 'security'. It really inhibits normal work so much that security is probably reduced.
Any machine should have tcpdump, netcat, lsof, strace as well. If you want to make it more secure - well set permissions appropriately and/or use selinux/apparmor.
Hell, may as well put osquery on it as well. Why make life difficult for people to do their jobs?
At an interview I was asked how to diagnose a running program. I mentioned strace of course, but they were also looking for gdb use. I've not had gdb on any prod machine for 'security reasons'. :-(
1. https://dougvitale.wordpress.com/2011/12/21/deprecated-linux...
[1] https://github.com/ecki/net-tools/blob/master/lib/pathnames....
strace -e open ss -s