⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme

📁 very comprehensive example, windows WDM driver development ex The use of drive technology can s
💻
📖 第 1 页 / 共 4 页
字号:
"open" -- clearly wrong.  [Some systems may not even *have* the "udp connectedsocket" concept, and netcat in its current form will not work for UDP at all.]If -z is specified and only one UDP port is probed, netcat's exit statusreflects whether the connection was "open" or "refused" as with TCP.It may also be that UDP packets are being blocked by filters with no ICMP errorreturns, in which case everything will time out and return "open".  This allsounds backwards, but that's how UDP works.  If you're not sure, try "echow00gumz | nc -u -w 2 target 7" to see if you can reach its UDP echo port atall.  You should have no trouble using a BSD-flavor system to scan for UDParound your own network, although flooding a target with the high activity that-z generates will cause it to occasionally drop packets and indicate false"opens".  A more "correct" way to do this is collect and analyze the ICMPerrors, as does SATAN's "udp_scan" backend, but then again there's no guaranteethat the ICMP gets back to you either.  Udp_scan also does the zero-byteprobes but is excruciatingly careful to calculate its own round-trip timingaverage and dynamically set its own response timeouts along with decoding anyICMP received.  Netcat uses a much sleazier method which is nonetheless quiteeffective.  Cisco routers are known to have a "dead time" in between ICMPresponses about unreachable UDP ports, so a fast scan of a cisco will showalmost everything "open".  If you are looking for a specific UDP service, youcan construct a file containing the right bytes to trigger a response from theother end and send that as standard input.  Netcat will read up to 8K of thefile and send the same data to every UDP port given.  Note that you must use atimeout in this case [as would any other UDP client application] since thetwo-write probe only happens if -z is specified.Many telnet servers insist on a specific set of option negotiations beforepresenting a login banner.  On a raw connection you will see this as smallamount of binary gook.  My attempts to create fixed input bytes to make atelnetd happy worked some places but failed against newer BSD-flavor ones,possibly due to timing problems, but there are a couple of much betterworkarounds.  First, compile with -DTELNET and use -t if you just want to getpast the option negotiation and talk to something on a telnet port.  You willstill see the binary gook -- in fact you'll see a lot more of it as the optionsare responded to behind the scenes.  The telnet responder does NOT update thetotal byte count, or show up in the hex dump -- it just responds negatively toany options read from the incoming data stream.  If you want to use a normalfull-blown telnet to get to something but also want some of netcat's featuresinvolved like settable ports or timeouts, construct a tiny "foo" script:	#! /bin/sh	exec nc -otheroptions targethost 23and then do	nc -l -p someport -e foo localhost &	telnet localhost someportand your telnet should connect transparently through the exec'ed netcat tothe target, using whatever options you supplied in the "foo" script.  Don'tuse -t inside the script, or you'll wind up sending *two* option responses.I've observed inconsistent behavior under some Linuxes [perhaps just olderones?] when binding in listen mode.  Sometimes netcat binds only to "localhost"if invoked with no address or port arguments, and sometimes it is unable tobind to a specific address for listening if something else is already listeningon "any".  The former problem can be worked around by specifying "-s 0.0.0.0",which will do the right thing despite netcat claiming that it's listening on[127.0.0.1].  This is a known problem -- for example, there's a mention of itin the makefile for SOCKS.  On the flip side, binding to localhost and sendingpackets to some other machine doesn't work as you'd expect -- they go out withthe source address of the sending interface instead.  The Linux kernel containsa specific check to ensure that packets from 127.0.0.1 are never sent to thewire; other kernels may contain similar code.  Linux, of course, *still*doesn't support source-routing, but they claim that it and many other networkimprovements are at least breathing hard.There are several possible errors associated with making TCP connections, butto specifically see anything other than "refused", one must wait the fullkernel-defined timeout for a connection to fail.  Netcat's mechanism ofwrapping an alarm timer around the connect prevents the *real* network errorfrom being returned -- "errno" at that point indicates "interrupted systemcall" since the connect attempt was interrupted.  Some old 4.3 BSD kernelswould actually return things like "host unreachable" immediately if that wasthe case, but most newer kernels seem to wait the full timeout and *then* passback the real error.  Go figure.  In this case, I'd argue that the old way wasbetter, despite those same kernels generally being the ones that tear down*established* TCP connections when ICMP-bombed.Incoming socket options are passed to applications by the kernel in thekernel's own internal format.  The socket-options structure for source-routingcontains the "first-hop" IP address first, followed by the rest of the realoptions list.  The kernel uses this as is when sending reply packets -- thestructure is therefore designed to be more useful to the kernel than to humans,but the hex dump of it that netcat produces is still useful to have.Kernels treat source-routing options somewhat oddly, but it sort of makes senseonce one understands what's going on internally.  The options list of addressesmust contain hop1, hop2, ..., destination.  When a source-routed packet is sentby the kernel [at least BSD], the actual destination address becomes irrelevantbecause it is replaced with "hop1", "hop1" is removed from the options list,and all the other addresses in the list are shifted up to fill the hole.  Thusthe outbound packet is sent from your chosen source address to the first*gateway*, and the options list now contains hop2, ..., destination.  Duringall this address shuffling, the kernel does NOT change the pointer value, whichis why it is useful to be able to set the pointer yourself -- you can constructsome really bizarre return paths, and send your traffic fairly directly to thetarget but around some larger loop on the way back.  Some Sun kernels seem tonever flip the source-route around if it contains less than three hops, neverreset the pointer anyway, and tries to send the packet [with options containinga "completed" source route!!] directly back to the source.  This is way broken,of course.  [Maybe ipforwarding has to be on?  I haven't had an opportunity tobeat on it thoroughly yet.]"Credits" section: The original idea for netcat fell out of a long-standingdesire and fruitless search for a tool resembling it and having the samefeatures.  After reading some other network code and realizing just how manycool things about sockets could be controlled by the calling user, I startedon the basics and the rest fell together pretty quickly.  Some port-scanningideas were taken from Venema/Farmer's SATAN tool kit, and Pluvius' "pscan"utility.  Healthy amounts of BSD kernel source were perused in an attempt todope out socket options and source-route handling; additional help was obtainedfrom Dave Borman's telnet sources.  The select loop is loosely based on fairlywell-known code from "rsh" and Richard Stevens' "sock" program [which itself issort of a "netcat" with more obscure features], with some more paranoidsanity-checking thrown in to guard against the distinct likelihood that thereare subtleties about such things I still don't understand.  I found theargument-hiding method cleanly implemented in Barrett's "deslogin"; reading theline as input allows greater versatility and is much less prone to causebizarre problems than the more common trick of overwriting the argv array.After the first release, several people contributed portability fixes; they arecredited in generic.h and the Makefile.  Lauren Burka inspired the ascii artfor this revised document.  Dean Gaudet at Wired supplied a precursor tothe hex-dump code, and mudge@l0pht.com originally experimented with andsupplied code for the telnet-options responder.  Outbound "-e <prog>" resultedfrom a need to quietly bypass a firewall installation.  Other suggestions andpatches have rolled in for which I am always grateful, but there are only 26hours per day and a discussion of feature creep near the end of this document.Netcat was written with the Russian railroad in mind -- conservatively builtand solid, but it *will* get you there.  While the coding style is fairly"tight", I have attempted to present it cleanly [keeping *my* lines under 80characters, dammit] and put in plenty of comments as to why certain thingsare done.  Items I know to be questionable are clearly marked with "XXX".Source code was made to be modified, but determining where to start isdifficult with some of the tangles of spaghetti code that are out there.Here are some of the major points I feel are worth mentioning about netcat'sinternal design, whether or not you agree with my approach.Except for generic.h, which changes to adapt more platforms, netcat is a singlesource file.  This has the distinct advantage of only having to include headersonce and not having to re-declare all my functions in a billion differentplaces.  I have attempted to contain all the gross who's-got-what-.h-filethings in one small dumping ground.  Functions are placed "dependencies-first",such that when the compiler runs into the calls later, it already knows thetype and arguments and won't complain.  No function prototyping -- not even the__P(()) crock -- is used, since it is more portable and a file of this size iseasy enough to check manually.  Each function has a standard-format commentahead of it, which is easily found using the regexp " :$".  I freely use gotos.Loops and if-clauses are made as small and non-nested as possible, and the endsof same *marked* for clarity [I wish everyone would do this!!].Large structures and buffers are all malloc()ed up on the fly, slightly largerthan the size asked for and zeroed out.  This reduces the chances of damagefrom those "end of the buffer" fencepost errors or runaway pointers escapingoff the end.  These things are permanent per run, so nothing needs to be freeduntil the program exits.File descriptor zero is always expected to be standard input, even if it isclosed.  If a new network descriptor winds up being zero, a different one isasked for which will be nonzero, and fd zero is simply left kicking aroundfor the rest of the run.  Why?  Because everything else assumes that stdin isalways zero and "netfd" is always positive.  This may seem silly, but it was alot easier to code.  The new fd is obtained directly as a new socket, becausetrying to simply dup() a new fd broke subsequent socket-style use of the new fdunder Solaris' stupid streams handling in the socket library.The catch-all message and error handlers are implemented with an ample list ofphoney arguments to get around various problems with varargs.  Varargs seemslike deliberate obfuscation in the first place, and using it would alsorequire use of vfprintf() which not all platforms support.  The trailingsleep in bail() is to allow output to flush, which is sometimes needed ifnetcat is already on the other end of a network connection.The reader may notice that the section that does DNS lookups seems muchgnarlier and more confusing than other parts.  This is NOT MY FAULT.  Thesockaddr and hostent abstractions are an abortion that forces the coder todeal with it.  Then again, a lot of BSD kernel code looks like similarstruct-pointer hell.  I try to straighten it out somewhat by defining my ownHINF structure, containing names, ascii-format IP addresses, and binary IPaddresses.  I fill this structure exactly once per host argument, and squirreleverything safely away and handy for whatever wants to reference it later.Where many other network apps use the FIONBIO ioctl to set non-blocking I/Oon network sockets, netcat uses straightforward blocking I/O everywhere.This makes everything very lock-step, relying on the network and filesystemlayers to feed in data when needed.  Data read in is completely written outbefore any more is fetched.  This may not be quite the right thing to do undersome OSes that don't do timed select() right, but this remains to be seen.The hexdump routine is written to be as fast as possible, which is why it doesso much work itself instead of just sprintf()ing everything together.  Eachdump line is built into a single buffer and atomically written out using thelowest level I/O calls.  Further improvements could undoubtedly be made byusing writev() and eliminating all sprintf()s, but it seems to fly right alongas is.  If both exec-a-prog mode and a hexdump file is asked for, the hexdumpflag is deliberately turned off to avoid creating random zero-length files.Files are opened in "truncate" mode; if you want "append" mode instead, changethe open flags in main().main() may look a bit hairy, but that's only because it has to go down theargv list and handle multiple ports, random mode, and exit status.  Effortshave been made to place a minimum of code inside the getopt() loop.  Any realwork is sent off to functions in what is hopefully a straightforward way.Obligatory vendor-bash: If "nc" had become a standard utility years ago,the commercial vendors would have likely packaged it setuid root and with-DGAPING_SECURITY_HOLE turned on but not documented.  It is hoped that netcatwill aid people in finding and fixing the no-brainer holes of this sort thatkeep appearing, by allowing easier experimentation with the "bare metal" ofthe network layer.It could be argued that netcat already has too many features.  I have triedto avoid "feature creep" by limiting netcat's base functionality only to thosethings which are truly relevant to making network connections and the everydayassociated DNS lossage we're used to.  Option switches already have slightlyoverloaded functionality.  Random port mode is sort of pushing it.  Thehex-dump feature went in later because it *is* genuinely useful.  Thetelnet-responder code *almost* verges on the gratuitous, especially since itmucks with the data stream, and is left as an optional piece.  Many people haveasked for example "how 'bout adding encryption?" and my response is that suchthings should be separate entities that could pipe their data *through* netcatinstead of having their own networking code.  I am therefore not completelyenthusiastic about adding any more features to this thing, although you arestill free to send along any mods you think are useful.Nonetheless, at this point I think of netcat as my tcp/ip swiss army knife,and the numerous companion programs and scripts to go with it as duct tape.Duct tape of course has a light side and a dark side and binds the universetogether, and if I wrap enough of it around what I'm trying to accomplish,it *will* work.  Alternatively, if netcat is a large hammer, there are manynetwork protocols that are increasingly looking like nails by now..._H* 960320 v1.10 RELEASE -- happy spring!

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -