Skip to content

Instantly share code, notes, and snippets.

@ksose
Created January 30, 2012 16:14
Show Gist options
  • Save ksose/1705205 to your computer and use it in GitHub Desktop.
Save ksose/1705205 to your computer and use it in GitHub Desktop.
pipe list
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct _FILE_DIRECTORY_INFORMATION {
ULONG NextEntryOffset;
ULONG FileIndex;
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
LARGE_INTEGER EndOfFile;
LARGE_INTEGER AllocationSize;
ULONG FileAttributes;
ULONG FileNameLength;
BYTE FileName;
} FILE_DIRECTORY_INFORMATION, *PFILE_DIRECTORY_INFORMATION;
typedef struct _IO_STATUS_BLOCK {
union {
NTSTATUS Status;
PVOID Pointer;
};
ULONG_PTR Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
#define STATUS_INFO_LENGTH_MISMATCH 0xc0000004
#define STATUS_NO_MORE_FILES 0x80000006
int main()
{
DWORD (WINAPI *NtQueryDirectoryFile)(HANDLE, HANDLE, PVOID, PVOID, PIO_STATUS_BLOCK, PFILE_DIRECTORY_INFORMATION, ULONG, ULONG, ULONG, ULONG, ULONG)
= (DWORD (WINAPI *)(HANDLE, HANDLE, PVOID, PVOID, PIO_STATUS_BLOCK, PFILE_DIRECTORY_INFORMATION, ULONG, ULONG, ULONG, ULONG, ULONG))
GetProcAddress(LoadLibrary("ntdll"), "NtQueryDirectoryFile");
HANDLE f_handle = CreateFile("\\\\.\\Pipe\\",
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
NULL,
NULL);
LONG ret, restart = 1;
IO_STATUS_BLOCK io_block = {0};
PFILE_DIRECTORY_INFORMATION file_info = (PFILE_DIRECTORY_INFORMATION)malloc(0x10000);
while(1)
{
ret = NtQueryDirectoryFile(f_handle, NULL, 0, 0, &io_block, file_info, 0x10000, 1, 0, 0, restart);
if (ret < 0)
break;
while(file_info->NextEntryOffset)
{
PBYTE file_name_w = (PBYTE)calloc(1, file_info->FileNameLength+2);
memcpy(file_name_w, &file_info->FileName, file_info->FileNameLength);
memcpy(file_name_w + file_info->FileNameLength, "\x00\x00", 2);
PBYTE file_name = (PBYTE)calloc(1, (file_info->FileNameLength/2)+1);
wcstombs((char *)file_name, (wchar_t *)file_name_w, file_info->FileNameLength/2);
printf("%s\n", file_name);
file_info = (PFILE_DIRECTORY_INFORMATION)((ULONG)file_info + file_info->NextEntryOffset);
free(file_name_w);
free(file_name);
}
restart = 0;
}
free(file_info);
CloseHandle(f_handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment