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

 

 


Tema destacado:


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [SC] Simple Local Shell
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] 2 Ir Abajo Respuesta Imprimir
Autor Tema: [SC] Simple Local Shell  (Leído 4,421 veces)
Jhonjhon_123

Desconectado Desconectado

Mensajes: 6



Ver Perfil WWW
[SC] Simple Local Shell
« en: 6 Enero 2012, 20:08 pm »

Hola gente!

Pues andaba un poco aburrido ayer y me desidi a crear una shell local, con unas modificaiones podran meterla en un subproseso, una socket, o lo que se les ocurra   :rolleyes:

Les dejo el codigo y un ejemplo de uso

Código
  1. ' ****************************************************************************************************************************** '
  2. '
  3. ' --- Autor: Jhonjhon_123 (Jhon Jairo Pro Developer)
  4. ' --- Versión: 1.0
  5. ' --- Descripción: Shell a nivel local en windows
  6. ' --- Fallos y Mejoras: MSN; j.j.g.p@hotmail.com
  7. ' --- Licencia: GNU General Public License
  8. '
  9. ' ****************************************************************************************************************************** '
  10. Option Explicit
  11.  
  12. Private Declare Function PeekNamedPipe Lib "kernel32" (ByVal hNamedPipe As Long, lpBuffer As Any, ByVal nBufferSize As Long, lpBytesRead As Long, lpTotalBytesAvail As Long, lpBytesLeftThisMessage As Long) As Long
  13. Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
  14. Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
  15.  
  16. Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As Any, ByVal nSize As Long) As Long
  17. Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
  18. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  19.  
  20. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
  21.  
  22. Private Declare Function DuplicateHandle Lib "kernel32" (ByVal hSourceProcessHandle As Long, ByVal hSourceHandle As Long, ByVal hTargetProcessHandle As Long, lpTargetHandle As Long, ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwOptions As Long) As Long
  23. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
  24.  
  25. Private Const STARTF_USESTDHANDLES          As Long = &H100
  26. Private Const STARTF_USESHOWWINDOW          As Long = &H1
  27. Private Const DUPLICATE_SAME_ACCESS         As Long = &H2
  28. Private Const NORMAL_PRIORITY_CLASS         As Long = &H20
  29.  
  30.  
  31. Private Type SECURITY_ATTRIBUTES
  32.    nLength                                As Long
  33.    lpSecurityDescriptor                   As Long
  34.    bInheritHandle                         As Long
  35. End Type
  36.  
  37. Private Type STARTUPINFO
  38.    cb                                     As Long
  39.    lpReserved                             As String
  40.    lpDesktop                              As String
  41.    lpTitle                                As String
  42.    dwX                                    As Long
  43.    dwY                                    As Long
  44.    dwXSize                                As Long
  45.    dwYSize                                As Long
  46.    dwXCountChars                          As Long
  47.    dwYCountChars                          As Long
  48.    dwFillAttribute                        As Long
  49.    dwFlags                                As Long
  50.    wShowWindow                            As Integer
  51.    cbReserved2                            As Integer
  52.    lpReserved2                            As Long
  53.    hStdInput                              As Long
  54.    hStdOutput                             As Long
  55.    hStdError                              As Long
  56. End Type
  57.  
  58. Private Type PROCESS_INFORMATION
  59.    hProcess                               As Long
  60.    hThread                                As Long
  61.    dwProcessID                            As Long
  62.    dwThreadId                             As Long
  63. End Type
  64.  
  65. Dim lHInput As Long
  66. Dim lHOutput As Long
  67. Dim lCmdID As Long
  68.  
  69. Public Sub StopShell()
  70.  
  71. If lHInput > 0 Then Call CloseHandle(lHInput)
  72.  
  73. If lHOutput > 0 Then Call CloseHandle(lHOutput)
  74.  
  75. If lCmdID > 0 Then Call TerminateProcess(lCmdID, ByVal 0&): Call CloseHandle(lCmdID)
  76.  
  77. End Sub
  78.  
  79. Public Function GetOutTextShell(sOut As String) As Boolean
  80. Dim bBuffer() As Byte
  81. Dim lLen As Long
  82. Dim bRes As Boolean
  83. Dim lLenBuff As Long
  84.  
  85. bRes = CBool(PeekNamedPipe(lHOutput, 0&, 0&, 0&, lLen, 0&))
  86.  
  87. If Not bRes Then Exit Function
  88.  
  89. If lLen <= 0 Then Exit Function
  90.  
  91. ReDim bBuffer(lLen)
  92.  
  93. If ReadFile(lHOutput, bBuffer(0), lLen, lLenBuff, ByVal 0&) = 0 Then Exit Function
  94.  
  95. sOut = Left(StrConv(bBuffer, vbUnicode), lLenBuff)
  96.  
  97. GetOutTextShell = True
  98.  
  99. End Function
  100.  
  101. Public Sub SendToShell(sCMD As String)
  102. Dim sBytes() As Byte
  103. Dim BytesWritten As Long
  104.  
  105. If lHInput = 0 Then Exit Sub
  106. sCMD = sCMD & vbNewLine
  107. sBytes = StrConv(sCMD, vbFromUnicode)
  108.  
  109. If WriteFile(lHInput, ByVal sCMD, Len(sCMD), BytesWritten, 0&) = 0 Then
  110.    Exit Sub
  111. End If
  112.  
  113. End Sub
  114.  
  115. Public Function StartShell() As Boolean
  116. On Error GoTo Error
  117.  
  118. Dim tSecurityAttributes As SECURITY_ATTRIBUTES
  119. Dim tStartInfo          As STARTUPINFO
  120. Dim tProcessInfo        As PROCESS_INFORMATION
  121. Dim lCurrentID          As Long
  122.  
  123. lCurrentID = GetCurrentProcess()
  124.  
  125. With tStartInfo
  126.    .cb = Len(tStartInfo)
  127.    .dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW
  128. End With
  129.  
  130. With tSecurityAttributes
  131.    .nLength = Len(tSecurityAttributes)
  132.    .bInheritHandle = 1
  133. End With
  134.  
  135. If CreatePipe(lHOutput, tStartInfo.hStdOutput, tSecurityAttributes, 0) = 0 Then
  136.    GoTo Error
  137. End If
  138.  
  139. If CreatePipe(tStartInfo.hStdInput, lHInput, tSecurityAttributes, 0) = 0 Then
  140.    GoTo Error
  141. End If
  142.  
  143. If DuplicateHandle(lCurrentID, tStartInfo.hStdOutput, lCurrentID, tStartInfo.hStdError, 0&, True, DUPLICATE_SAME_ACCESS) = 0 Then
  144.    GoTo Error
  145. End If
  146.  
  147. If CreateProcess(vbNullString, "cmd", tSecurityAttributes, tSecurityAttributes, 1, NORMAL_PRIORITY_CLASS, ByVal 0&, vbNullString, tStartInfo, tProcessInfo) = 0 Then
  148.    GoTo Error
  149. End If
  150.  
  151. With tProcessInfo
  152.    Call CloseHandle(.hThread)
  153.  
  154.    lCmdID = .hProcess
  155.  
  156.    If .dwProcessID > 0 And .hProcess > 0 Then
  157.        StartShell = True
  158.    Else
  159.        GoTo Error
  160.    End If
  161. End With
  162.  
  163. Exit Function
  164. Error:
  165. Call StopShell
  166. StartShell = False
  167.  
  168. End Function
  169.  

Descarga Ejemplo: http://www.multiupload.com/1NVDU8LZSP

Saludos ::)


« Última modificación: 6 Enero 2012, 20:13 pm por Jhonjhon_123 » En línea

Elemental Code


Desconectado Desconectado

Mensajes: 622


Im beyond the system


Ver Perfil
Re: [SC] Simple Local Shell
« Respuesta #1 en: 6 Enero 2012, 21:36 pm »

mmm pipes....

Nunca entendi que son o como funcionan  :-(


En línea

I CODE FOR $$$
Programo por $$$
Hago tareas, trabajos para la facultad, lo que sea en VB6.0

Mis programas
Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [SC] Simple Local Shell
« Respuesta #2 en: 7 Enero 2012, 17:07 pm »

Mal estructurado e indentado :rolleyes:
Código:
http://foro.elhacker.net/programacion_visual_basic/ayuda_con_cmd_pipe_vb6-t277687.0.html;msg1367077#msg1367077
http://www.ngssoftware.com/research/papers/WritingSmallShellcode.pdf
Este es un buen ejemplo de como redirigir el flujo de datos entre un proceso (cmd) y el socket :)
En línea

Jhonjhon_123

Desconectado Desconectado

Mensajes: 6



Ver Perfil WWW
Re: [SC] Simple Local Shell
« Respuesta #3 en: 7 Enero 2012, 18:00 pm »

Mal estructurado e indentado :rolleyes:
Código:
http://foro.elhacker.net/programacion_visual_basic/ayuda_con_cmd_pipe_vb6-t277687.0.html;msg1367077#msg1367077
http://www.ngssoftware.com/research/papers/WritingSmallShellcode.pdf
Este es un buen ejemplo de como redirigir el flujo de datos entre un proceso (cmd) y el socket :)

yeah, ley tus codes sobre la shell remota, pero la quise hacer local :rolleyes:

Saludos  ;D
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [SC] Simple Local Shell
« Respuesta #4 en: 7 Enero 2012, 19:59 pm »

No es mio, es de Cobein.
Puse los enlaces para que veas que se puede pasar directamente el handle sin necesidad de crear un Pipe... revisa el código y lee las definiciones de las APIs en la MSDN.
En línea

Jhonjhon_123

Desconectado Desconectado

Mensajes: 6



Ver Perfil WWW
Re: [SC] Simple Local Shell
« Respuesta #5 en: 7 Enero 2012, 20:07 pm »

vale, pero esos son handles a una socket, pero a nivel local que alternativa hay a un Pipe?

Saludos :D
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [SC] Simple Local Shell
« Respuesta #6 en: 7 Enero 2012, 20:40 pm »

Sí. Es por eso que te digo que revises el código y las definiciones en la MSDN.
En línea

Jhonjhon_123

Desconectado Desconectado

Mensajes: 6



Ver Perfil WWW
Re: [SC] Simple Local Shell
« Respuesta #7 en: 7 Enero 2012, 21:52 pm »

men, pk dices que anda mal estructurado?
En línea

Fakedo0r

Desconectado Desconectado

Mensajes: 21


Fuera de compás, en una de las 12 dimensiones...


Ver Perfil WWW
Re: [SC] Simple Local Shell
« Respuesta #8 en: 7 Enero 2012, 21:57 pm »

Muy bonito el código, muy bien estructurado!!! Lo leeré  ;D

PD: Alguno tiene el ego demasiado levantado, hay que ser un poco humilde  :P
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [SC] Simple Local Shell
« Respuesta #9 en: 8 Enero 2012, 13:05 pm »

@Jhonjhon_123: Ya te respondí por privado que el problema de estructuración está sobretodo en como manejas los errores... Pero como Fakedo0r tampoco parece ver esos fallos en la estructura voy a añadir una explicación.

A mí, personalmente, me parece que haces las comprobaciones de forma incorrecta. Buscas siempre el caso negativo y finalizas. Esto añade código extra en el ejecutable final. Es por eso que te recomiendo utilizar condiciónales anidados... He rehecho el código para que comprendas a que me refiero:
Código
  1. Public Sub StopShell()
  2.    Call CloseHandle(lHInput)
  3.    Call CloseHandle(lHOutput)
  4.    Call TerminateProcess(lCmdID, ByVal 0&)
  5.    Call CloseHandle(lCmdID)
  6. End Sub
  7.  
  8. Public Function GetOutTextShell(sOut As String) As Boolean
  9.    Dim bBuffer()   As Byte
  10.    Dim lLen        As Long
  11.    Dim lLenBuff    As Long
  12.  
  13.    If PeekNamedPipe(lHOutput, 0&, 0&, 0&, lLen, 0&) Then
  14.        ReDim bBuffer(lLen)
  15.        If ReadFile(lHOutput, bBuffer(0), lLen, lLenBuff, ByVal 0&) Then
  16.            sOut = Left$(StrConv(bBuffer, vbUnicode), lLenBuff)
  17.            GetOutTextShell = True
  18.        End If
  19.    End If
  20. End Function
  21.  
  22. Public Sub SendToShell(sCMD As String)
  23.    Dim sBytes() As Byte
  24.    Dim BytesWritten As Long
  25.  
  26.    If lHInput Then
  27.        sBytes = StrConv(sCMD & vbNewLine, vbFromUnicode)
  28.        Call WriteFile(lHInput, ByVal sCMD, Len(sCMD), BytesWritten, 0&)
  29.    End If
  30. End Sub
  31.  
  32. Public Function StartShell() As Boolean
  33.    Dim tSecurityAttributes As SECURITY_ATTRIBUTES
  34.    Dim tStartInfo          As STARTUPINFO
  35.    Dim tProcessInfo        As PROCESS_INFORMATION
  36.    Dim lCurrentID          As Long
  37.  
  38.    lCurrentID = GetCurrentProcess()
  39.  
  40.    With tStartInfo
  41.        .cb = Len(tStartInfo)
  42.        .dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW
  43.    End With
  44.  
  45.    With tSecurityAttributes
  46.        .nLength = Len(tSecurityAttributes)
  47.        .bInheritHandle = 1
  48.    End With
  49.  
  50.    If CreatePipe(lHOutput, tStartInfo.hStdOutput, tSecurityAttributes, 0) Then
  51.        If CreatePipe(tStartInfo.hStdInput, lHInput, tSecurityAttributes, 0) Then
  52.            If DuplicateHandle(lCurrentID, tStartInfo.hStdOutput, lCurrentID, tStartInfo.hStdError, 0&, True, DUPLICATE_SAME_ACCESS) Then
  53.                If CreateProcess(vbNullString, "cmd", tSecurityAttributes, tSecurityAttributes, 1, NORMAL_PRIORITY_CLASS, ByVal 0&, vbNullString, tStartInfo, tProcessInfo) Then
  54.                    Call CloseHandle(tProcessInfo.hThread)
  55.                    StartShell = True
  56.                    Exit Function
  57.                End If
  58.            End If
  59.        End If
  60.    End If
  61.    Call StopShell
  62. End Function
Algunas aclaraciones más:
Si lees las definiciones de las APIs que usas como te dije, te darás cuenta también que haces comprobaciones duplicadas... Si el retorno de X API es true, esto implica otras cosas también.
Pueden parecer más feos los condicionales anidados pero: Es más rápido. Menos código compilado. Puedes (si lo deseas) controlar los errores por separado.

Espero que entiendas a que me refiero, y si lo tienes en cuenta para otras veces perfecto,sino también.
En línea

Páginas: [1] 2 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Conexiones de Conexion de area local por Rundell Shell
Programación Visual Basic
oskoa 0 1,206 Último mensaje 18 Junio 2009, 21:50 pm
por oskoa
Shell.php a shell en ruby
Nivel Web
madridserginho 1 4,131 Último mensaje 10 Julio 2009, 11:27 am
por Ivanchuk
[AYUDA] Shell local.
Programación Visual Basic
79137913 2 1,864 Último mensaje 2 Febrero 2011, 16:22 pm
por 79137913
Una shell parecida a Shell Dark2.0
Análisis y Diseño de Malware
GeorgeEcuador 3 3,132 Último mensaje 11 Agosto 2011, 22:51 pm
por [Zero]
[PHP Shell] Poison Shell 1.0
PHP
BigBear 1 3,802 Último mensaje 6 Julio 2012, 02:42 am
por sniperroms
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines