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

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Imprime texto de la nada. Tuberias (Solucionado)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Imprime texto de la nada. Tuberias (Solucionado)  (Leído 1,934 veces)
Usuario887


Desconectado Desconectado

Mensajes: 310


Ver Perfil
Imprime texto de la nada. Tuberias (Solucionado)
« en: 13 Noviembre 2021, 18:08 pm »

Tengo este codigo:

Código
  1. #include <stdio.h>
  2. #include <windows.h>
  3.  
  4. int error(char *szErr, int errcode)
  5. {
  6.    printf("\r\nError: RTL: %s: %d", szErr, errcode);
  7.    return errcode;
  8. }
  9.  
  10. DWORD AsynchronouslyListen (HANDLE *phPipeOutRd)
  11. {
  12.    BYTE szBuffer[BUFSIZ];
  13.    DWORD dwBytesn;
  14.  
  15.    while(ReadFile(*phPipeOutRd,
  16.                   szBuffer,
  17.                   BUFSIZ,
  18.                   &dwBytesn,
  19.                   NULL))
  20.    {
  21.        szBuffer[dwBytesn]='\0';
  22.        printf("%s", szBuffer);
  23.    }
  24.  
  25.    return 0;
  26. }
  27.  
  28. int main()
  29. {
  30.    HANDLE hPipeOutRd, hPipeOutWr,
  31.           hPipeInRd, hPipeInWr;
  32.  
  33.    SECURITY_ATTRIBUTES sa;
  34.    STARTUPINFO si;
  35.    PROCESS_INFORMATION pi;
  36.  
  37.    DWORD dwBytesn;
  38.    BYTE szBuffer[BUFSIZ];
  39.  
  40.    HANDLE hAsynchronouslyListenT;
  41.  
  42.    printf("\r\nCreating pipes for communication... ");
  43.  
  44.    sa.nLength=sizeof(SECURITY_ATTRIBUTES);
  45.    sa.lpSecurityDescriptor=NULL;
  46.    sa.bInheritHandle=TRUE;
  47.  
  48.    if(!CreatePipe(&hPipeInRd, &hPipeInWr, &sa, 0))
  49.    {
  50.        error("CreatePipe()", GetLastError());
  51.    }
  52.  
  53.    if(!CreatePipe(&hPipeOutRd, &hPipeOutWr, &sa, 0))
  54.    {
  55.        error("CreatePipe()",GetLastError());
  56.    }
  57.  
  58.    printf("ok ");
  59.  
  60.    printf("\r\nCreating process... ");
  61.  
  62.    ZeroMemory(&si, sizeof(STARTUPINFO));
  63.    si.cb=sizeof(STARTUPINFO);
  64.    si.dwFlags=STARTF_USESTDHANDLES;
  65.  
  66.    si.hStdError=si.hStdOutput=hPipeOutWr;
  67.    si.hStdInput=hPipeInRd;
  68.  
  69.    if(!CreateProcess("C:\\Windows\\System32\\cmd.exe",
  70.                      NULL,
  71.                      NULL,
  72.                      NULL,
  73.                      TRUE,
  74.                      0,
  75.                      NULL,
  76.                      NULL,
  77.                      &si,
  78.                      &pi))
  79.    {
  80.        error("CreateProcess()", GetLastError());
  81.    }
  82.  
  83.    printf("ok ");
  84.  
  85.    printf("\r\nCreating thread... ");
  86.  
  87.    sa.nLength=sizeof(SECURITY_ATTRIBUTES);
  88.    sa.lpSecurityDescriptor=NULL;
  89.    sa.bInheritHandle=TRUE;
  90.  
  91.    if((hAsynchronouslyListenT=CreateThread(&sa,
  92.                                            0,
  93.                                            (LPTHREAD_START_ROUTINE)AsynchronouslyListen,
  94.                                            &hPipeOutRd,
  95.                                            0,
  96.                                            NULL))==NULL)
  97.    {
  98.        error("CreateThread()", GetLastError());
  99.    }
  100.  
  101.    printf("ok ");
  102.  
  103.    printf("\r\n");
  104.  
  105.    while(strcmp(szBuffer, "exit")&&\
  106.          strcmp(szBuffer, "end"))
  107.    {
  108.        printf("\r\n");
  109.  
  110.        ZeroMemory(szBuffer, BUFSIZ);
  111.        gets(szBuffer);
  112.        szBuffer[strlen(szBuffer)]='\n';
  113.        szBuffer[strlen(szBuffer)+1]=0;
  114.  
  115.        if(!WriteFile(hPipeInWr,
  116.                      szBuffer,
  117.                      strlen(szBuffer),
  118.                      &dwBytesn,
  119.                      NULL))
  120.        {
  121.            error("WriteFile()", GetLastError());
  122.        }
  123.    }
  124.  
  125.    ExitProcess(0);
  126. }
  127.  

El cual produce esta salida:

Citar
Creating pipes for communication... ok
Creating process... ok
Creating thread... ok

Microsoft Windows [Version 10.0.19043.1348]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Programming\Documents\Pipe exercise\1>echo hola

echo hola
hola

C:\Users\Programming\Documents\Pipe exercise\1>

Imprime la cadena del input a la tuberia  :huh: :huh: :huh: :huh: :huh: :huh:

He puesto breakpoints (improvisados) aldededor del programa y nada que doy con la parte que imprime esto. Se que no es WriteFile y sospecho que es ReadFile pero no puedo estar seguro porque se esta ejecutando al mismo tiempo que el main thread

¿Alguien sabe a que se debe?



Es el proceso hijo.

CMD.EXE hace eco del comando de entrada... Porque hay dos "gets" aqui... El del proceso hijo mas el del proceso padre... Mira tu que interesante...


« Última modificación: 13 Noviembre 2021, 18:56 pm por marax » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Solucionado][Batch] Find (buscar archivos por fecha) y tuberias
Scripting
Baranoides 2 14,732 Último mensaje 13 Enero 2012, 21:05 pm
por Baranoides
imprime mal fecha (solucionado)
PHP
basickdagger 7 7,127 Último mensaje 20 Agosto 2013, 19:54 pm
por basickdagger
PORQUE IMPRIME LAS GRAFICAS Y NO EL TEXTO
Java
jelsir 3 1,592 Último mensaje 24 Abril 2014, 18:19 pm
por jelsir
Programa que imprime un número entre 0 y un billón como texto [SWI-Prolog]
Programación General
_TTFH_3500 0 2,019 Último mensaje 8 Octubre 2020, 23:34 pm
por _TTFH_3500
Pipes (tuberias) sincronas, estancadas (Solucionado)
Programación General
Usuario887 0 2,039 Último mensaje 11 Noviembre 2021, 22:29 pm
por Usuario887
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines