• Inicio
  • Buscar
  • Ingresar
  • Registrarse

    Starfield: el juego que revolucionará el espacio y la tecnología

    • Hack x Crack - Comunidad de Seguridad informática »
    • Programación »
    • Scripting »
    • [Ruby] LocateIP 0.3
    • Imprimir
    Páginas: [1]   Ir Abajo

    Autor Tema: [Ruby] LocateIP 0.3  (Leído 7166 veces)

    Desconectado BigBear

    • { L5 } Smurf
    • *****
    • Mensajes: 594
      • Ver Perfil
    [Ruby] LocateIP 0.3
    « en: Junio 27, 2015, 01:18:43 am »
    Un simple script en Ruby para localizar una IP y sus DNS.

    Version consola :

    Código: Ruby
    1. #!usr/bin/ruby
    2. #LocateIP 0.3
    3. #(C) Doddy Hackman 2015
    4.  
    5. require "open-uri"
    6. require "net/http"  
    7. require "resolv"
    8.  
    9. # Functions
    10.  
    11. def get_ip(hostname)
    12.         begin
    13.                 return Resolv.getaddress(hostname)
    14.         rescue
    15.                 return "Error"
    16.         end
    17. end
    18.  
    19. def toma(web)
    20.         begin
    21.                 return open(web, "User-Agent" => "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0").read
    22.         rescue
    23.                 return "Error"
    24.         end
    25. end
    26.  
    27. def response_code(web)
    28.         begin
    29.                 return Net::HTTP.get_response(URI(web)) .code
    30.         rescue
    31.                 return "404"
    32.         end
    33. end
    34.  
    35. def tomar(web,arg)
    36.         begin
    37.                 headers = {"User-Agent" => "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"}
    38.                 uri = URI(web)
    39.                 http = Net::HTTP.new(uri.host, uri.port)
    40.                 return http.post(uri.path,arg, headers).body
    41.         rescue
    42.                 return "Error"
    43.         end
    44. end
    45.  
    46. def uso
    47.         print "\n[+] Sintax : ruby locateip.rb <target>\n"
    48. end
    49.  
    50. def  head
    51.         print "\n\n-- == LocateIP 0.3 == --\n\n"
    52. end
    53.  
    54. def copyright
    55.         print "\n\n-- == (C) Doddy Hackman 2015 == --\n\n"
    56. end
    57.  
    58. def locateip(target)
    59.  
    60.         print "\n[+] Getting IP ...\n"
    61.  
    62.         ip = get_ip(target)
    63.  
    64.         print "\n[+] IP : "+ip+"\n"
    65.  
    66.         web = "http://www.melissadata.com/lookups/iplocation.asp"
    67.         print "\n[+] Locating ...\n\n"
    68.  
    69.         code = tomar(web,"ipaddress="+ip+"&btn=Submit")
    70.  
    71.         if code=~/City<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
    72.                 print "[+] City : "+$2+"\n"
    73.         else
    74.                 print "[+] City : Not Found\n"
    75.         end
    76.  
    77.         if code=~/Country<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
    78.                 print "[+] Country : "+$2+"\n"
    79.         else
    80.                 print "[+] Country : Not Found\n"
    81.         end
    82.  
    83.         if code=~/State or Region<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
    84.                 print "[+] State or Region : "+$2+"\n";
    85.         else
    86.                 print "[+] State of Region : Not Found\n"
    87.         end
    88.  
    89.         print "\n[+] Getting DNS ...\n\n"
    90.  
    91.         control = "0"
    92.  
    93.         code = toma("http://www.ip-adress.com/reverse_ip/"+ip)
    94.  
    95.         dnss = code.scan(/whois\/(.*?)\">Whois/)
    96.  
    97.         dnss.flatten.each do |dns|
    98.                 begin
    99.                         if dns != ""
    100.                                 control = "1"
    101.                                 print "[+] DNS Found : "+dns
    102.                         end
    103.                 end
    104.         end
    105.  
    106.         if control=="0"
    107.                 print "\n[-] DNS Not Found\n"
    108.         end
    109. end
    110.  
    111. target = ARGV[0]
    112.  
    113. head()
    114.  
    115. if !target
    116.         uso()
    117. else
    118.         locateip(target)
    119. end
    120.  
    121. copyright()
    122.  
    123. #The End ?
    124.  

    Version Tk :

    Código: Ruby
    1. #!usr/bin/ruby
    2. #LocateIP 0.3
    3. #(C) Doddy Hackman 2015
    4.  
    5. require "tk"
    6. require "open-uri"
    7. require "net/http"
    8. require "resolv"
    9.  
    10. # Functions
    11.  
    12. def get_ip(hostname)
    13.         begin
    14.                 return Resolv.getaddress(hostname)
    15.         rescue
    16.                 return "Error"
    17.         end
    18. end
    19.  
    20. def toma(web)
    21.         begin
    22.                 return open(web, "User-Agent" => "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0").read
    23.         rescue
    24.                 return "Error"
    25.         end
    26. end
    27.  
    28. def response_code(web)
    29.         begin
    30.                 return Net::HTTP.get_response(URI(web)) .code
    31.         rescue
    32.                 return "404"
    33.         end
    34. end
    35.  
    36. def tomar(web,arg)
    37.         begin
    38.                 headers = {"User-Agent" => "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"}
    39.                 uri = URI(web)
    40.                 http = Net::HTTP.new(uri.host, uri.port)
    41.                 return http.post(uri.path,arg, headers).body
    42.         rescue
    43.                 return "Error"
    44.         end
    45. end
    46.  
    47. #
    48.  
    49. window = TkRoot.new { title "LocateIP 0.3 (C) Doddy Hackman 2015" ; background "black" }
    50. window['geometry'] = '300x300-20+10'
    51.  
    52. TkLabel.new(window) do
    53.         background "black"
    54.         foreground "yellow"
    55.         text "    Target : "
    56.         place('relx'=>"0.1",'rely'=>"0.1")
    57. end
    58.  
    59. target = TkEntry.new(window){
    60.         background "black"
    61.         foreground "yellow"
    62.         width 25
    63.         place('relx'=>0.3,'rely'=>0.1)
    64. }
    65.  
    66. TkLabel.new(window) do
    67.         background "black"
    68.         foreground "yellow"
    69.         text "Console"
    70.         place('relx'=>0.4,'rely'=>0.2)
    71. end
    72.  
    73. console =TkText.new(window) do
    74.         background "black"
    75.         foreground "yellow"
    76.         width 30
    77.         height 10
    78.         place('relx'=>0.1,'rely'=>0.3)
    79. end
    80.  
    81. TkButton.new(window) do
    82.         text "Search"
    83.         background "black"
    84.         foreground "yellow"
    85.         width 17
    86.         activebackground "yellow"
    87.         highlightbackground  "yellow"
    88.         command proc{
    89.        
    90.                 target = target.value.to_s
    91.        
    92.                 console.insert("end",  "[+] Getting IP ...\n")
    93.  
    94.                 ip = get_ip(target)
    95.  
    96.                 web = "http://www.melissadata.com/lookups/iplocation.asp"
    97.  
    98.                 console.insert("end", "\n[+] Locating ...\n\n")
    99.  
    100.                 code = tomar(web,"ipaddress="+ip+"&btn=Submit")
    101.  
    102.                 if code=~/City<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
    103.                         console.insert("end", "[+] City : "+$2+"\n")
    104.                 else
    105.                         console.insert("end", "[+] City : Not Found\n")
    106.                 end
    107.  
    108.                 if code=~/Country<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
    109.                         console.insert("end","[+] Country : "+$2+"\n")
    110.                 else
    111.                         console.insert("end", "[+] Country : Not Found\n")
    112.                 end
    113.  
    114.                 if code=~/State or Region<\/td><td align=(.*)><b>(.*)<\/b><\/td>/
    115.                         console.insert("end", "[+] State or Region : "+$2+"\n")
    116.                 else
    117.                         console.insert("end","[+] State of Region : Not Found\n")
    118.                 end
    119.  
    120.                 console.insert("end","\n[+] Getting DNS ...\n\n")
    121.  
    122.                 control = "0"
    123.  
    124.                 code = toma("http://www.ip-adress.com/reverse_ip/"+ip)
    125.  
    126.                 dnss = code.scan(/whois\/(.*?)\">Whois/)
    127.  
    128.                 dnss.flatten.each do |dns|
    129.                         begin
    130.                                 if dns != ""
    131.                                         control = "1"
    132.                                         console.insert("end", "[+] DNS Found : "+dns)
    133.                                 end
    134.                         end
    135.                 end
    136.  
    137.                 if control=="0"
    138.                         console.insert("end","\n[-] DNS Not Found\n")
    139.                 end
    140.  
    141.                 console.insert("end","\n\n[+] Finished")
    142.                
    143.         }
    144.         place('relx'=>0.3,'rely'=>0.9)
    145. end
    146.  
    147. Tk.mainloop
    148.  
    149. #The End ?
    150.  

    Una imagen :



    Eso es todo.
    En línea

    Desconectado tryger

    • Moderador
    • { L2 } Nativo Digital
    • **
    • Mensajes: 118
      • Ver Perfil
    Re:[Ruby] LocateIP 0.3
    « Respuesta #1 en: Junio 27, 2015, 12:04:31 pm »
    Buen code, Doddy. Solo que en la primera linea deberia ser "#!/usr/bin/ruby" ya que como lo tienes ahora, el sistema buscará el interprete dentro del path actual.

    Salu2 :)

    Edit: tambien podrias poner un salto de linea despues de imprimir un dns, que quedan en la misma linea.
    « Última modificación: Junio 27, 2015, 12:12:30 pm por tryger »
    En línea

    Desconectado <[Zoro]248>

    • { L7 } Juanker
    • *******
    • Mensajes: 1435
      • Ver Perfil
    Re:[Ruby] LocateIP 0.3
    « Respuesta #2 en: Julio 06, 2015, 04:23:02 am »
    Buen codigo, como crear el ejecutable  :o ??
    « Última modificación: Julio 06, 2015, 04:24:55 am por <[Zoro]248> »
    En línea
    La Ignorancia es Felicidad pero el Conocimiento te hace Libre!, pero al final tu decides

    Desconectado BigBear

    • { L5 } Smurf
    • *****
    • Mensajes: 594
      • Ver Perfil
    Re:[Ruby] LocateIP 0.3
    « Respuesta #3 en: Julio 12, 2015, 12:01:50 am »
    Cita de: <[Zoro]248> en Julio 06, 2015, 04:23:02 am
    Buen codigo, como crear el ejecutable  :o ??

    con rubyscript2exe-0.5.3.rb , fijate en el manual indexado en esta misma seccion , el post se llama "iniciando en ruby" , leelo para entender como se hace.
    En línea

    Desconectado Krakakanok

    • Co-Administrador
    • { L7 } Juanker
    • ******
    • Mensajes: 1518
    • Los buenos nunca se esconden.
      • Ver Perfil
    Re:[Ruby] LocateIP 0.3
    « Respuesta #4 en: Julio 16, 2015, 11:56:36 am »
    yo soy mas de utilizar env en el shebang pero bueno, cuestion de gustos.

    Buen code como siempre Doddy.

    Saludos.

    PD: me encanto la pagina de pruebas xDDD.
    En línea
    No hagas nada cuyo resultado sea incierto.
    monitor mode enabled on usa0

    Desconectado <[Zoro]248>

    • { L7 } Juanker
    • *******
    • Mensajes: 1435
      • Ver Perfil
    Re:[Ruby] LocateIP 0.3
    « Respuesta #5 en: Julio 25, 2015, 07:46:57 am »
    Cita de: Doddy en Julio 12, 2015, 12:01:50 am
    Cita de: <[Zoro]248> en Julio 06, 2015, 04:23:02 am
    Buen codigo, como crear el ejecutable  :o ??

    con rubyscript2exe-0.5.3.rb , fijate en el manual indexado en esta misma seccion , el post se llama "iniciando en ruby" , leelo para entender como se hace.


    Gracias!!
    En línea
    La Ignorancia es Felicidad pero el Conocimiento te hace Libre!, pero al final tu decides

    • Imprimir
    Páginas: [1]   Ir Arriba
    • Hack x Crack - Comunidad de Seguridad informática »
    • Programación »
    • Scripting »
    • [Ruby] LocateIP 0.3
     

    • SMF | SMF © 2013, Simple Machines
    • XHTML
    • RSS
    • WAP2
    Va un mudo y le dice a un sordo: Hack x Crack usa cookies. Pues eso... Learn more