Семинар по реверсу - Гришаев и Островной
parent
453774dc91
commit
f69fa9a14b
@ -0,0 +1,54 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
unsigned int MakeChecksum(unsigned char *buffer, int len)
|
||||||
|
{
|
||||||
|
unsigned int result;
|
||||||
|
|
||||||
|
result = 0;
|
||||||
|
for (int i = 0; i < len; i = i + 1) {
|
||||||
|
result = (result << 3 | result >> 0x1d) ^ buffer[i];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//0: [CHECKSUM] - 4 bytes
|
||||||
|
//[
|
||||||
|
//4: [TIME] - 4 bytes
|
||||||
|
//8: [PAYLOAD + HEADER LEN] - 1 byte
|
||||||
|
//9: [TYPE] - 1 byte
|
||||||
|
//10: [PAYLOAD LEN] - 1 byte
|
||||||
|
//11: [PAYLOAD]
|
||||||
|
//]
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
unsigned char type = 0x2A;
|
||||||
|
unsigned char payload[] = "g1mm3_th3_k3y";
|
||||||
|
unsigned char payload_len = strlen(payload);
|
||||||
|
|
||||||
|
unsigned char *flag_payload = malloc(payload_len);
|
||||||
|
for (int i = 0; i < payload_len; ++i)
|
||||||
|
flag_payload[i] = payload[i] ^ 42;
|
||||||
|
|
||||||
|
unsigned char packet_len = payload_len + 7;
|
||||||
|
time_t create_time = time(NULL);
|
||||||
|
|
||||||
|
char *packet = calloc(payload_len + 0xb, sizeof(char));
|
||||||
|
|
||||||
|
memcpy(&packet[11], flag_payload, payload_len);
|
||||||
|
memcpy(&packet[10], &payload_len, 1);
|
||||||
|
memcpy(&packet[9], &type, 1);
|
||||||
|
memcpy(&packet[8], &packet_len, 1);
|
||||||
|
memcpy(&packet[4], &create_time, 4);
|
||||||
|
|
||||||
|
int crc = MakeChecksum(packet + 4, packet_len);
|
||||||
|
memcpy(packet, &crc, 4);
|
||||||
|
|
||||||
|
// Output
|
||||||
|
fwrite(packet, 1, payload_len + 0xb, stdout);
|
||||||
|
|
||||||
|
free(packet);
|
||||||
|
free(flag_payload);
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue