elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [RUBY] [APPORTE PARA WINDOWS] PATHS v0.3 - Una utilidad para el PATH
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [RUBY] [APPORTE PARA WINDOWS] PATHS v0.3 - Una utilidad para el PATH  (Leído 4,106 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
[RUBY] [APPORTE PARA WINDOWS] PATHS v0.3 - Una utilidad para el PATH
« en: 13 Noviembre 2012, 23:44 pm »

    

  PATHS v0.3
   By Elektro H@cker  













   Opciones:

   /? (or) -help  | Muestra la ayuda.

   -l (or) -list  | Lista las entradas del PATH.

   -c (or) -clean | Limpia entradas inválidas o duplicados en los PATH.

   -r (or) -reset | Resetea el PATH al PATH de Windows por defecto.

   -a (or) -add   | Añade una entrada.

   -d (or) -del   | Elimina una entrada.

   -add -current  | Fuerza el añadido de una entrada al "Current_User" PATH.

   -add -local    | Fuerza el añadido de una entrada al "Local_Machine" PATH.



   Ejemplos:

   PATHS -l
  
  • Lista (Indexa) las entradas dle path.

   PATHS -a "C:\Folder"
  
  • Añade la entrada "C:\Folder" al LOCAL_MACHINE PATH.

   PATHS -a current "C:\Folder"
  
  • Añade la entrada "C:\Folder" al CURRENT_USER PATH..

   PATHS -d "3"
  
  • Elimina la entrada nº3 de la lista.

   PATHS -d "C:\Folder"
  
  • Elimina la entrada "C:\Folder".


Compilado: http://elektrostudios.tk/PATHS.exe

PATHS.rb

(El código está algo sucio, pero lo que importa es que funciona xD)

Código
  1. require 'win32/registry'
  2. require 'rainbow'
  3.  
  4.  
  5. # PATHS v0.3
  6. #
  7. # By Elektro H@cker
  8.  
  9.  
  10. # Description:
  11. # -----------
  12. # This is a tool to manage the windows PATH enviroment.
  13. # Add, delete, backup, clean, list, and reset the PATH.
  14.  
  15.  
  16. exit if Object.const_defined?(:Ocra)
  17.  
  18.  
  19. def logo()
  20.  print "
  21.   PATHS v0.3
  22.  
  23.   By Elektro H@cker
  24.  
  25. ".foreground(:white)
  26. end
  27.  
  28.  
  29. def help()
  30.  print '
  31.  
  32.   Options:
  33.  
  34.   /? (or) -help   | Show this info.
  35.  
  36.   -l (or) -list   | List the entries.
  37.  
  38.   -b (or) -backup | Backup the entries.  
  39.  
  40.   -c (or) -clean  | Clean duplicates and invalid directories in the paths.
  41.  
  42.   -r (or) -reset  | Reset the paths to the Windows defaults.
  43.  
  44.   -a (or) -add    | Add a entry.
  45.  
  46.   -d (or) -del    | Delete a entry.
  47.  
  48.   -add -current   | Force adding a entry into the current user path.
  49.  
  50.   -add -local     | Force adding a entry into the local machine path.
  51.  
  52.  
  53.  
  54.   Examples:
  55.  
  56.   PATHS -l
  57.   [+] Indexes all the entries.
  58.  
  59.   PATHS -a "C:\Folder"
  60.   [+] Adds a entry into the local path.
  61.  
  62.   PATHS -a current "C:\Folder"
  63.   [+] Adds a entry into the current user path.
  64.  
  65.   PATHS -d "3"
  66.   [+] Deletes the 3rd entry of the indexed list.
  67.  
  68.   PATHS -d "C:\Folder"
  69.   [+] Deletes a entry.
  70.  
  71.  '
  72.  exit
  73. end
  74.  
  75.  
  76. def error(kind)
  77.  print "[+] ERROR"
  78.  if kind == "pos"      then print "\n    Index #{ARGV[1]} is out of range, only #{$pos} entries.\n" end
  79.  if kind == "notfound" then print "\n    Directory \"#{ARGV[1]}\" not found in PATH.\n" end
  80.  exit
  81. end
  82.  
  83.  
  84. def args()
  85.  if ARGV.empty?                                   then get_paths("visible") end
  86.  if ARGV[0] == "/?"    or ARGV[0] =~ /^-help$/i   then help()               end  
  87.  if ARGV[0] =~ /^-l$/i or ARGV[0] =~ /^-list$/i   then get_paths("visible") end
  88.  if ARGV[0] =~ /^-b$/i or ARGV[0] =~ /^-backup$/i then backup_path()        end
  89.  if ARGV[0] =~ /^-c$/i or ARGV[0] =~ /^-clean$/i  then clean_path()         end    
  90.  if ARGV[0] =~ /^-d$/i or ARGV[0] =~ /^-del$/i    then del_path()           end
  91.  if ARGV[0] =~ /^-a$/i or ARGV[0] =~ /^-add$/i    then add_path()           end
  92.  if ARGV[0] =~ /^-r$/i or ARGV[0] =~ /^-reset$/i  then reset_path()         end
  93. end
  94.  
  95.  
  96. def get_paths(visibility)
  97.  
  98.  $pos = 0
  99.  
  100.  # HKCU path
  101.  if not visibility == "hidden" then puts "\n   [+] Current User PATH:\n\n" end
  102.  Win32::Registry::HKEY_CURRENT_USER.open('Environment') do |reg|
  103.    for dir in reg['Path'].split(";").sort do
  104.  $pos = $pos+1
  105.  dir = dir.gsub(/^PATH=/, "")
  106.      instance_variable_set "@_#{$pos}", dir + "?CURRENT_USER"
  107.      if not File.directory? dir then invalid = "(Directory doesn't exist)".foreground(:red).bright else invalid ="" end
  108.      if not visibility == "hidden"
  109.        if $pos < 10 then puts "    #{$pos.to_s} = #{dir} #{invalid}" else puts "    #{$pos.to_s}= #{dir} #{invalid}"end
  110.      end
  111.    end
  112.  end
  113.  
  114.  # HKLM path
  115.  if not visibility == "hidden" then puts "\n\n   [+] Local Machine PATH:\n\n" end
  116.  Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment') do |reg|
  117.    for dir in reg['Path'].split(";").sort do
  118.  $pos = $pos+1
  119.  dir = dir.gsub(/^PATH=/, "")
  120.      instance_variable_set "@_#{$pos}", dir + "?LOCAL_MACHINE"
  121.      if not File.directory? dir then invalid = "(Directory doesn't exist)".foreground(:red).bright else invalid ="" end
  122.      if not visibility == "hidden"
  123.        if $pos < 10 then puts "    #{$pos.to_s} = #{dir} #{invalid}" else puts "    #{$pos.to_s}= #{dir} #{invalid}"end
  124.      end
  125.    end
  126.  end
  127.  if not visibility == "hidden" then exit end
  128.  $max_pos = $pos
  129.  
  130. end
  131.  
  132.  
  133. def add_path()
  134.  
  135.  if ARGV[1] =~ /^-current$/ then key = "current" else key = "local" end
  136.  
  137.  # HKCU path
  138.  if key == "current"
  139.    Win32::Registry::HKEY_CURRENT_USER.open('Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg|
  140.      value = reg['Path']
  141.      reg.write('Path', Win32::Registry::REG_SZ, "#{value};#{ARGV.last}")
  142.      puts "[+] Entry added in User PATH: #{ARGV.last}"
  143.    end
  144.  end
  145.  
  146.  # HKLM path
  147.  if key == "local"
  148.    Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg|
  149.      value = reg['Path']
  150.      reg.write('Path', Win32::Registry::REG_SZ, "#{value};#{ARGV.last}")
  151.      puts "[+] Entry added in Local PATH: #{ARGV.last}"
  152.    end
  153.  end
  154.  
  155. end
  156.  
  157.  
  158. def del_path()
  159.  
  160.    get_paths("hidden")
  161.    final_path = ""
  162.    found      = 0
  163.    notfound   = 0
  164.  
  165.  if ARGV[1] =~ /^[1-9]+$/
  166.  
  167.    choose     = instance_variable_get "@_#{ARGV[1]}"
  168.  
  169.    if ARGV[1].to_i > $max_pos.to_i then error("pos") end
  170.  
  171.    # HKCU PATH index deletion
  172.    if choose["?CURRENT_USER"]
  173.      Win32::Registry::HKEY_CURRENT_USER.open('Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg|
  174.        value = reg['Path']
  175.        for dir in reg['Path'].split(";").sort do
  176.          if not dir == choose.split("?").first then final_path << ";" + dir end
  177.        end
  178.        reg.write('Path', Win32::Registry::REG_SZ, final_path[1..-1])
  179.      end
  180.      puts "[+] Entry deleted in User PATH: #{choose.split("?").first}"
  181.    end
  182.  
  183.    # HKLM PATH index deletion
  184.    if choose["?LOCAL_MACHINE"]
  185.      Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg|
  186.        value = reg['Path']
  187.        for dir in reg['Path'].split(";").sort do
  188.          if not dir == choose.split("?").first then final_path << ";" + dir end
  189.        end
  190.        reg.write('Path', Win32::Registry::REG_SZ, final_path[1..-1])
  191.      end
  192.      puts "[+] Entry deleted in Local PATH: #{choose.split("?").first}"
  193.    end
  194.  
  195.  elsif
  196.  
  197.    # HKCU PATH str deletion
  198.      Win32::Registry::HKEY_CURRENT_USER.open('Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg|
  199.        value = reg['Path']
  200.        for dir in reg['Path'].split(";").sort do
  201.          if not dir =~ /^#{Regexp.escape(ARGV[1])}$/i then final_path << ";" + dir else found = "yes" end
  202.        end
  203.        reg.write('Path', Win32::Registry::REG_SZ, final_path[1..-1])
  204.        if found == "yes" then puts "[+] Entry deleted in User PATH: #{ARGV[1]}" else notfound = 1 end
  205.      end
  206.  
  207.    # HKLM PATH str deletion
  208.      final_path = ""
  209.      found = ""
  210.      Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg|
  211.        value = reg['Path']
  212.        for dir in reg['Path'].split(";").sort do
  213.          if not dir =~ /^#{Regexp.escape(ARGV[1])}$/i then final_path << ";" + dir else found = "yes" end
  214.        end
  215.        reg.write('Path', Win32::Registry::REG_SZ, final_path[1..-1])
  216.        if found == "yes" then puts "[+] Entry deleted in Local PATH: #{ARGV[1]}" else notfound = notfound+1 end
  217.        if notfound == 2 then error("notfound") end
  218.      end
  219.  
  220.    end
  221.  
  222. end
  223.  
  224.  
  225. def backup_path()
  226.  
  227.  # if type REG_EXPAND_SZ convert it first to REG_SZ
  228.  # HKCU path
  229.    Win32::Registry::HKEY_CURRENT_USER.open('Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg|
  230.      value = reg['Path']
  231.      reg.write('Path', Win32::Registry::REG_SZ, value)
  232.    end
  233.  # HKLM path
  234.    Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg|
  235.      value = reg['Path']
  236.      reg.write('Path', Win32::Registry::REG_SZ, value)
  237.    end
  238.  # Conversion end
  239.  
  240.  system('Regedit.exe /E "%TEMP%\HKCU PATH.reg" "HKEY_CURRENT_USER\Environment"')
  241.  system('Regedit.exe /E "%TEMP%\HKLM PATH.reg"  "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"')
  242.  system('type "%TEMP%\HKCU PATH.reg" | Findstr /I "\"PATH\" HKEY_CURRENT_USER Registry" > "%USERPROFILE%\Desktop\HKCU PATH %DATE:/=-%.reg"')
  243.  system('type "%TEMP%\HKLM PATH.reg" | Findstr /I "\"PATH\" HKEY_LOCAL_MACHINE Registry" > "%USERPROFILE%\Desktop\HKLM PATH %DATE:/=-%.reg"')
  244.  puts "[+] A copy of your current PATH saved at your desktop."
  245.  exit
  246. end
  247.  
  248.  
  249. def reset_path()
  250.  Win32::Registry::HKEY_CURRENT_USER.open('Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg| reg.write('Path', Win32::Registry::REG_SZ, 'C:\Windows;C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\syswow64;C:\Windows\System32\WindowsPowerShell\v1.0') end
  251.  Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg| reg.write('Path', Win32::Registry::REG_SZ, 'C:\Windows;C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\syswow64;C:\Windows\System32\WindowsPowerShell\v1.0') end
  252.  puts "[+] PATH restored to Windows defaults."
  253. end
  254.  
  255.  
  256. def clean_path()
  257.  
  258.  puts "\n[+] Searching invalid or duplicated entries in the PATH...\n\n"
  259.  
  260.  # HKCU PATH
  261.  final_path = ""
  262.  Win32::Registry::HKEY_CURRENT_USER.open('Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg|
  263.    value = reg['Path']
  264.    for dir in reg['Path'].split(";").sort do
  265.      if File.directory? dir and not final_path[/#{Regexp.escape(dir)}$/i] then final_path << ";" + dir else puts "[+] Entry deleted in User PATH: #{dir}" end
  266.    end
  267.    reg.write('Path', Win32::Registry::REG_SZ, final_path[1..-1])
  268.  end
  269.  
  270.  # HKLM PATH
  271.  final_path = ""
  272.  Win32::Registry::HKEY_LOCAL_MACHINE.open('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', Win32::Registry::KEY_ALL_ACCESS) do |reg|
  273.    value = reg['Path']
  274.    for dir in reg['Path'].split(";").sort do
  275.      if File.directory? dir and not final_path[/#{Regexp.escape(dir)}$/i] then final_path << ";" + dir else puts "[+] Entry deleted in Local PATH: #{dir}" end
  276.    end
  277.    reg.write('Path', Win32::Registry::REG_SZ, final_path[1..-1])
  278.  end
  279.  
  280.  puts "\n[+] PATH is cleaned.\n\n"
  281.  
  282. end
  283.  
  284. logo()
  285. args()
  286.  
  287. exit


« Última modificación: 5 Marzo 2013, 15:33 pm por EleKtro H@cker » En línea

z3nth10n


Desconectado Desconectado

Mensajes: 1.583


"Jack of all trades, master of none." - Zenthion


Ver Perfil WWW
Re: [RUBY] [APPORTE PARA WINDOWS] PATHS v0.1 - Una utilidad para el PATH
« Respuesta #1 en: 13 Noviembre 2012, 23:47 pm »

Buen aporte, oye tio tu como te dosificas el tiempo? xD


En línea


Interesados hablad por Discord.
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: [RUBY] [APPORTE PARA WINDOWS] PATHS v0.1 - Una utilidad para el PATH
« Respuesta #2 en: 14 Noviembre 2012, 00:05 am »

Buen aporte, oye tio tu como te dosificas el tiempo? xD

(Gracias)

Tengo una máquina del tiempo

Un saludo.
« Última modificación: 8 Abril 2013, 13:32 pm por EleKtro H@cker » En línea

z3nth10n


Desconectado Desconectado

Mensajes: 1.583


"Jack of all trades, master of none." - Zenthion


Ver Perfil WWW
Re: [RUBY] [APPORTE PARA WINDOWS] PATHS v0.1 - Una utilidad para el PATH
« Respuesta #3 en: 14 Noviembre 2012, 10:41 am »


Jaja, que bueno, oye te agrego a msn y hablamos ok?
« Última modificación: 8 Abril 2013, 13:32 pm por EleKtro H@cker » En línea


Interesados hablad por Discord.
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.788



Ver Perfil
Re: [RUBY] [APPORTE PARA WINDOWS] PATHS v0.1 - Una utilidad para el PATH
« Respuesta #4 en: 5 Marzo 2013, 15:33 pm »

NUEVA VERSIÓN 0.3

http://elektrostudios.tk/PATHS.exe

Corregido un error crítico:
Si en el PC el valor de la clave PATH era de typo REG_EXPAND_SZ no podía funcionar ningún parámetro del Script.

Nada más,
saludos!
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[SOURCE] PATHS (Administra las entradas de las variables de entorno 'PATH' y...)
.NET (C#, VB.NET, ASP)
Eleкtro 1 4,306 Último mensaje 8 Septiembre 2013, 11:46 am
por Eleкtro
Utilidad de particion de HD para espiar??
Hacking
Fullant 0 2,078 Último mensaje 19 Enero 2014, 12:43 pm
por Fullant
[SOURCE] PATHS (Administrador de la variable de entorno PATH y PATHEXT)
.NET (C#, VB.NET, ASP)
Eleкtro 2 2,921 Último mensaje 11 Junio 2015, 04:50 am
por Eleкtro
¿Qué es Big Data y para qué puede ser de utilidad?
Noticias
wolfbcn 0 872 Último mensaje 14 Febrero 2016, 14:32 pm
por wolfbcn
PATH Windows 8
Windows
ItzMaGiiicK 7 3,271 Último mensaje 12 Abril 2017, 18:03 pm
por Randomize
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines