TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Netstat without netstat

138 pointsby wolframioover 7 years ago

10 comments

deathanatosover 7 years ago
&gt; <i>Since I wasn’t root and couldn’t install any tools (guess I could have copied a netstat binary across)</i><p>If you have the ability to write anywhere to disk (e.g., even &#x2F;tmp, &#x2F;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.<p>(I didn&#x27;t have a working scp on a machine, and it was the ssh &quot;gateway&quot; 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.)
评论 #15977351 未加载
评论 #15980401 未加载
评论 #15977034 未加载
feelin_googleyover 7 years ago
AWK-less version. Assumes only sed and printf builtin.<p>Bonus: aligned columns[1]<p>(tested on 80x25 and only with text from blog, not actual &#x2F;proc&#x2F;net&#x2F;tcp)<p>[1] Hack. Probably there is a better way to do alignment using only printf; alas I only know a subset of printf features.<p><pre><code> #! &#x2F;bin&#x2F;sh printf &#x27;%s\t\t\t%s\n&#x27; Local Remote sed &#x27; &#x2F;: &#x2F;!d; s&#x2F;.*: &#x2F;&#x2F;; s&#x2F; &#x2F;-&#x2F;; s&#x2F; .*&#x2F;&#x2F;; s&#x2F;[0-9A-F][0-9A-F]&#x2F;0x&amp; &#x2F;g; s&#x2F; 0x&#x2F;&#x2F;4; s&#x2F; 0x&#x2F;&#x2F;7; s&#x2F;:&#x2F;&#x2F;g; s&#x2F;-&#x2F;&#x2F;; &#x27; &#x2F;proc&#x2F;net&#x2F;tcp \ |while read a b c d e g h i j k;do s=$(printf &#x27;%d.%d.%d.%d:%d %d.%d.%d.%d:%-22d\n&#x27; \ $d $c $b $a $e $j $i $h $g $k); l=${s%% *};r=${s#* }; if test ${#s} -lt 45;then printf &#x27;%s\t\t%s\n&#x27; $l $r;else printf &#x27;%s\t%s\n&#x27; $l $r;fi; done</code></pre>
lathiatover 7 years ago
The &#x27;modern&#x27; iputils alternative to netstat is &#x27;ss&#x27;. May or may not exist on some systems where netstat does not.<p>Good info, though. Lots of info to bad had in &#x2F;proc but needs parsing.
评论 #15977372 未加载
评论 #15977164 未加载
zx2c4over 7 years ago
Pro-tip: if you pop a shell, only use it to run your own dropper. Use locally available tools as little as possible. Automate your entire post-exploitation payload and cleanup and get out as soon as possible.<p>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.
评论 #15980281 未加载
评论 #15978912 未加载
评论 #15979548 未加载
chungyover 7 years ago
netstat and ifconfig tend to be deprecated on Linux in favor of ss and ip. I do have to wonder if ss was tried, but still, the learning experience is quite valuable. :)
评论 #15976299 未加载
discreditableover 7 years ago
I wonder if ss was available? I&#x27;d recommend looking over &quot;Deprecated Linux Networking Commands and their Replacements&quot;[1]. In the case of netstat, `ss -a` is a good place to start.<p>1. <a href="https:&#x2F;&#x2F;dougvitale.wordpress.com&#x2F;2011&#x2F;12&#x2F;21&#x2F;deprecated-linux-networking-commands-and-their-replacements&#x2F;" rel="nofollow">https:&#x2F;&#x2F;dougvitale.wordpress.com&#x2F;2011&#x2F;12&#x2F;21&#x2F;deprecated-linux...</a>
niftichover 7 years ago
I can&#x27;t speak to ss and ip, but apparently netstat actually operates by opening these exact files [1].<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;ecki&#x2F;net-tools&#x2F;blob&#x2F;master&#x2F;lib&#x2F;pathnames.h" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ecki&#x2F;net-tools&#x2F;blob&#x2F;master&#x2F;lib&#x2F;pathnames....</a>
评论 #15977377 未加载
_jomoover 7 years ago
Reminds me of an article shared a while ago on HN where someone deleted &#x2F; and ended up with all binaries gone but still had a working bash session and the &#x2F;proc fs. Can&#x27;t find the link, sadly.
devericxover 7 years ago
Super helpful article for a budding penetration tester such as myself! Thanks for sharing.
trobothamover 7 years ago
pretty interesting.