| |
| #include "../kernel.h" |
|
|
| |
| #define MAX_PORTS 1024 |
| #define SCAN_TCP 0 |
| #define SCAN_UDP 1 |
| #define SCAN_SYN 2 |
| #define SCAN_OPEN 1 |
| #define SCAN_CLOSED 0 |
|
|
| |
| typedef struct { u16 port; u8 proto; u8 state; char service[32]; } PortInfo; |
| static PortInfo scan_results[MAX_PORTS]; |
| static u32 scan_count; |
|
|
| |
| typedef struct { char hash[64]; char pass[32]; u32 attempts; } HashJob; |
| static HashJob crack_job; |
|
|
| |
| static inline u16 htons(u16 v) { return ((v&0xFF)<<8)|((v>>8)&0xFF); } |
| static inline u32 simple_hash(const char* s) { u32 h=5381; while(*s)h=((h<<5)+h)+*s++; return h; } |
|
|
| |
| void pentest_scan(u32 ip, u16 start, u16 end) { |
| scan_count = 0; |
| for(u16 port=start; port<=end && scan_count<MAX_PORTS; port++) { |
| u32 sock = socket_create(2, 1); |
| if(!sock) continue; |
| int r = socket_connect(sock, ip, port); |
| PortInfo* p = &scan_results[scan_count]; |
| p->port = port; p->proto = SCAN_TCP; |
| p->state = (r==0) ? SCAN_OPEN : SCAN_CLOSED; |
| if(p->state == SCAN_OPEN) { |
| if(port==22) { p->service[0]='s';p->service[1]='s';p->service[2]='h'; } |
| else if(port==80) { p->service[0]='h';p->service[1]='t';p->service[2]='t';p->service[3]='p'; } |
| else if(port==443) { p->service[0]='h';p->service[1]='t';p->service[2]='t';p->service[3]='p';p->service[4]='s'; } |
| } |
| scan_count++; |
| socket_close(sock); |
| } |
| } |
|
|
| |
| int pentest_brute(u32 ip, u16 port, const char* user, const char* pass) { |
| u32 sock = socket_create(2, 1); |
| if(!sock) return -1; |
| int r = socket_connect(sock, ip, port); |
| socket_close(sock); |
| return (r==0) ? 1 : 0; |
| } |
|
|
| |
| const char* pentest_crack(const char* hash_str, const char** wordlist, u32 count) { |
| for(u32 i=0; i<count; i++) { |
| const char* w = wordlist[i]; |
| if(!w) break; |
| u32 h = simple_hash(w); |
| u32 target = 0; for(const char* c=hash_str;*c;c++) target = target*10+(*c-'0'); |
| crack_job.attempts++; |
| if(h == target) return w; |
| } |
| return NULL; |
| } |
|
|
| |
| typedef struct { u8 bssid[6]; char essid[32]; u8 channel; u8 signal; u8 encryption; } WiFiNet; |
| static WiFiNet wifi_nets[64]; static u32 wifi_count; |
|
|
| void pentest_wifi_scan(void) { |
| wifi_count = 0; |
| for(u32 ch=1; ch<=13 && wifi_count<64; ch++) { |
| for(u32 net=0; net<3; net++) { |
| WiFiNet* w = &wifi_nets[wifi_count]; |
| w->channel = ch; w->signal = 50+ch*3; |
| w->essid[0]='W';w->essid[1]='i';w->essid[2]='F';w->essid[3]='i';w->essid[4]='0'+net; |
| w->encryption = 1; |
| wifi_count++; |
| } |
| } |
| } |
|
|
| |
| void pentest_report(void) { |
| outb(0xE9,'\n'); outb(0xE9,'='); outb(0xE9,'='); outb(0xE9,'\n'); |
| for(const char* c="PENTEST REPORT\n";*c;c++) outb(0xE9,*c); |
| |
| |
| u32 open_count = 0; |
| for(u32 i=0;i<scan_count;i++) if(scan_results[i].state==SCAN_OPEN) { |
| open_count++; |
| } |
| outb(0xE9,'O');outb(0xE9,'p');outb(0xE9,'e');outb(0xE9,'n');outb(0xE9,' ');outb(0xE9,':');outb(0xE9,' ');outb(0xE9,'0'+open_count/10);outb(0xE9,'0'+open_count%10);outb(0xE9,'\n'); |
| |
| |
| outb(0xE9,'W');outb(0xE9,'i');outb(0xE9,'F');outb(0xE9,'i');outb(0xE9,':');outb(0xE9,' ');outb(0xE9,'0'+wifi_count/10);outb(0xE9,'0'+wifi_count%10);outb(0xE9,'\n'); |
| } |
|
|