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

📄 readme

📁 very comprehensive example, windows WDM driver development ex The use of drive technology can s
💻
📖 第 1 页 / 共 4 页
字号:
about genuinely open connections.  Example: "nc -v -w 2 -z target 20-30" willtry connecting to every port between 20 and 30 [inclusive] at the target, andwill likely inform you about an FTP server, telnet server, and mailer along theway.  The -z switch prevents sending any data to a TCP connection and verylimited probe data to a UDP connection, and is thus useful as a fast scanningmode just to see what ports the target is listening on.  To limit scanningspeed if desired, -i will insert a delay between each port probe.  There aresome pitfalls with regard to UDP scanning, described later, but in general itworks well.For each range of ports specified, scanning is normally done downward withinthat range.  If the -r switch is used, scanning hops randomly around withinthat range and reports open ports as it finds them.  [If you want them listedin order regardless, pipe standard error through "sort"...]  In addition, ifrandom mode is in effect, the local source ports are also randomized.  Thisprevents netcat from exhibiting any kind of regular pattern in its scanning.You can exert fairly fine control over your scan by judicious use of -r andselected port ranges to cover.  If you use -r for a single connection, thesource port will have a random value above 8192, rather than the next one thekernel would have assigned you.  Note that selecting a specific local portwith -p overrides any local-port randomization.Many people are interested in testing network connectivity using IP sourcerouting, even if it's only to make sure their own firewalls are blockingsource-routed packets.  On systems that support it, the -g switch can be usedmultiple times [up to 8] to construct a loose-source-routed path for yourconnection, and the -G argument positions the "hop pointer" within the list.If your network allows source-routed traffic in and out, you can testconnectivity to your own services via remote points in the internet.  Note thatalthough newer BSD-flavor telnets also have source-routing capability, it isn'tclearly documented and the command syntax is somewhat clumsy.  Netcat'shandling of "-g" is modeled after "traceroute".Netcat tries its best to behave just like "cat".  It currently does nothing toterminal input modes, and does no end-of-line conversion.  Standard input froma terminal is read line by line with normal editing characters in effect.  Youcan freely suspend out of an interactive connection and resume.  ^C or whateveryour interrupt character is will make netcat close the network connection andexit.  A switch to place the terminal in raw mode has been considered, but sofar has not been necessary.  You can send raw binary data by reading it out ofa file or piping from another program, so more meaningful effort would be spentwriting an appropriate front-end driver.Netcat is not an "arbitrary packet generator", but the ability to talk to rawsockets and/or nit/bpf/dlpi may appear at some point.  Such things are clearlyuseful; I refer you to Darren Reed's excellent ip_filter package, which nowincludes a tool to construct and send raw packets with any contents you want.Example uses -- the light side==============================Again, this is a very partial list of possibilities, but it may get you tothink up more applications for netcat.  Driving netcat with simple shell orexpect scripts is an easy and flexible way to do fairly complex tasks,especially if you're not into coding network tools in C.  My coding isn'tparticularly strong either [although undoubtedly better after writing thisthing!], so I tend to construct bare-metal tools like this that I can triviallyplug into other applications.  Netcat doubles as a teaching tool -- one canlearn a great deal about more complex network protocols by trying to simulatethem through raw connections!An example of netcat as a backend for something else is the shell-scriptWeb browser, which simply asks for the relevant parts of a URL and pipes"GET /what/ever" into a netcat connection to the server.  I used to do thiswith telnet, and had to use calculated sleep times and other stupidity tokludge around telnet's limitations.  Netcat guarantees that I get the wholepage, and since it transfers all the data unmodified, I can even pull downbinary image files and display them elsewhere later.  Some folks may find theidea of a shell-script web browser silly and strange, but it starts up andgets me my info a hell of a lot faster than a GUI browser and doesn't hideany contents of links and forms and such.  This is included, as scripts/web,along with several other web-related examples.Netcat is an obvious replacement for telnet as a tool for talking to daemons.For example, it is easier to type "nc host 25", talk to someone's mailer, andjust ^C out than having to type ^]c or QUIT as telnet would require you to do.You can quickly catalog the services on your network by telling netcat toconnect to well-known services and collect greetings, or at least scan for openports.  You'll probably want to collect netcat's diagnostic messages in youroutput files, so be sure to include standard error in the output using`>& file' in *csh or `> file 2>&1' in bourne shell.A scanning example: "echo QUIT | nc -v -w 5 target 20-250 500-600 5990-7000"will inform you about a target's various well-known TCP servers, includingr-services, X, IRC, and maybe a few you didn't expect.  Sending in QUIT andusing the timeout will almost guarantee that you see some kind of greeting orerror from each service, which usually indicates what it is and what version.[Beware of the "chargen" port, though...]  SATAN uses exactly this technique tocollect host information, and indeed some of the ideas herein were taken fromthe SATAN backend tools.  If you script this up to try every host in yoursubnet space and just let it run, you will not only see all the services,you'll find out about hosts that aren't correctly listed in your DNS.  Then youcan compare new snapshots against old snapshots to see changes.  For goingafter particular services, a more intrusive example is in scripts/probe.Netcat can be used as a simple data transfer agent, and it doesn't reallymatter which end is the listener and which end is the client -- input at oneside arrives at the other side as output.  It is helpful to start the listenerat the receiving side with no timeout specified, and then give the sending sidea small timeout.  That way the listener stays listening until you contact it,and after data stops flowing the client will time out, shut down, and take thelistener with it.  Unless the intervening network is fraught with problems,this should be completely reliable, and you can always increase the timeout.  Atypical example of something "rsh" is often used for: on one side,	nc -l -p 1234 | uncompress -c | tar xvfp -and then on the other side	tar cfp - /some/dir | compress -c | nc -w 3 othermachine 1234will transfer the contents of a directory from one machine to another, withouthaving to worry about .rhosts files, user accounts, or inetd configurationsat either end.  Again, it matters not which is the listener or receiver; the"tarring" machine could just as easily be running the listener instead.  Onecould conceivably use a scheme like this for backups, by having cron-jobs fireup listeners and backup handlers [which can be restricted to specific addressesand ports between each other] and pipe "dump" or "tar" on one machine to "ddof=/dev/tapedrive" on another as usual.  Since netcat returns a nonzero exitstatus for a denied listener connection, scripts to handle such tasks couldeasily log and reject connect attempts from third parties, and then retry.Another simple data-transfer example: shipping things to a PC that doesn't haveany network applications yet except a TCP stack and a web browser.  Point thebrowser at an arbitrary port on a Unix server by telling it to downloadsomething like http://unixbox:4444/foo, and have a listener on the Unix sideready to ship out a file when the connect comes in.  The browser may pervertbinary data when told to save the URL, but you can dig the raw data out ofthe on-disk cache.If you build netcat with GAPING_SECURITY_HOLE defined, you can use it as an"inetd" substitute to test experimental network servers that would otherwiserun under "inetd".  A script or program will have its input and output hookedto the network the same way, perhaps sans some fancier signal handling.  Giventhat most network services do not bind to a particular local address, whetherthey are under "inetd" or not, it is possible for netcat avoid the "addressalready in use" error by binding to a specific address.  This lets you [asroot, for low ports] place netcat "in the way" of a standard service, sinceinbound connections are generally sent to such specifically-bound listenersfirst and fall back to the ones bound to "any".  This allows for a one-offexperimental simulation of some service, without having to screw around withinetd.conf.  Running with -v turned on and collecting a connection log fromstandard error is recommended.Netcat as well can make an outbound connection and then run a program or scripton the originating end, with input and output connected to the same networkport.  This "inverse inetd" capability could enhance the backup-server conceptdescribed above or help facilitate things such as a "network dialback" concept.The possibilities are many and varied here; if such things are intended assecurity mechanisms, it may be best to modify netcat specifically for thepurpose instead of wrapping such functions in scripts.Speaking of inetd, netcat will function perfectly well *under* inetd as a TCPconnection redirector for inbound services, like a "plug-gw" without theauthentication step.  This is very useful for doing stuff like redirectingtraffic through your firewall out to other places like web servers and mailhubs, while posing no risk to the firewall machine itself.  Put netcat behindinetd and tcp_wrappers, perhaps thusly:	www stream tcp nowait nobody /etc/tcpd /bin/nc -w 3 realwww 80and you have a simple and effective "application relay" with access controland logging.  Note use of the wait time as a "safety" in case realwww isn'treachable or the calling user aborts the connection -- otherwise the relay mayhang there forever.You can use netcat to generate huge amounts of useless network data forvarious performance testing.  For example, doing	yes AAAAAAAAAAAAAAAAAAAAAA | nc -v -v -l -p 2222 > /dev/nullon one side and then hitting it with	yes BBBBBBBBBBBBBBBBBBBBBB | nc othermachine 2222 > /dev/nullfrom another host will saturate your wires with A's and B's.  The "veryverbose" switch usage will tell you how many of each were sent and receivedafter you interrupt either side.  Using UDP mode produces tremendously MOREtrash per unit time in the form of fragmented 8 Kbyte mobygrams -- enough tostress-test kernels and network interfaces.  Firing random binary data intovarious network servers may help expose bugs in their input handling, whichnowadays is a popular thing to explore.  A simple example data-generator isgiven in data/data.c included in this package, along with a small collectionof canned input files to generate various packet contents.  This program isdocumented in its beginning comments, but of interest here is using "%r" togenerate random bytes at well-chosen points in a data stream.  If you cancrash your daemon, you likely have a security problem.The hex dump feature may be useful for debugging odd network protocols,especially if you don't have any network monitoring equipment handy or aren'troot where you'd need to run "tcpdump" or something.  Bind a listening netcatto a local port, and have it run a script which in turn runs another netcatto the real service and captures the hex dump to a log file.  This sets up atransparent relay between your local port and wherever the real service is.Be sure that the script-run netcat does *not* use -v, or the extra info itsends to standard error may confuse the protocol.  Note also that you cannothave the "listen/exec" netcat do the data capture, since once the connectionarrives it is no longer netcat that is running.Binding to an arbitrary local port allows you to simulate things like r-serviceclients, if you are root locally.  For example, feeding "^@root^@joe^@pwd^@"[where ^@ is a null, and root/joe could be any other local/remote usernamepair] into a "rsh" or "rlogin" server, FROM your port 1023 for example,duplicates what the server expects to receive.  Thus, you can test for insecure.rhosts files around your network without having to create new user accounts onyour client machine.  The program data/rservice.c can aid this process byconstructing the "rcmd" protocol bytes.  Doing this also prevents "rshd" fromtrying to create that separate standard-error socket and still gives you aninput path, as opposed to the usual action of "rsh -n".  Using netcat forthings like this can be really useful sometimes, because rsh and rlogingenerally want a host *name* as an argument and won't accept IP addresses.  Ifyour client-end DNS is hosed, as may be true when you're trying to extractbackup sets on to a dumb client, "netcat -n" wins where normal rsh/rlogin isuseless.If you are unsure that a remote syslogger is working, test it with netcat.Make a UDP connection to port 514 and type in "<0>message", which shouldcorrespond to "kern.emerg" and cause syslogd to scream into every file it hasopen [and possibly all over users' terminals].  You can tame this down byusing a different number and use netcat inside routine scripts to send syslogmessages to places that aren't configured in syslog.conf.  For example,"echo '<38>message' | nc -w 1 -u loggerhost 514" should send to auth.noticeon loggerhost.  The exact number may vary; check against your syslog.h first.Netcat provides several ways for you to test your own packet filters.  If youbind to a port normally protected against outside access and make a connectionto somewhere outside your own network, the return traffic will be coming toyour chosen port from the "outside" and should be blocked.  TCP may get throughif your filter passes all "ack syn", but it shouldn't be even doing that to lowports on your network.  Remember to test with UDP traffic as well!  If yourfilter passes at least outbound source-routed IP packets, bouncing a connectionback to yourself via some gateway outside your network will create "incoming"traffic with your source address, which should get dropped by a correctlyconfigured anti-spoofing filter.  This is a "non-test" if you're also droppingsource-routing, but it's good to be able to test for that too.  Any packetfilter worth its salt will be blocking source-routed packets in bothdirections, but you never know what interesting quirks you might turn up by

⌨️ 快捷键说明

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