Семинар по реверсу - Гришаев и Островной

master
Nihonium 5 months ago
parent 453774dc91
commit f69fa9a14b
Signed by: nihonium
GPG Key ID: 0251623741027CFC

@ -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);
}

@ -0,0 +1,64 @@
#include <stdio.h>
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <string.h>
#include <time.h>
#include <stdlib.h>
unsigned int MakeChecksum(unsigned char* param_1,unsigned long param_2)
{
unsigned int local_14;
unsigned long local_10;
local_14 = 0;
for (local_10 = 0; local_10 < param_2; local_10 = local_10 + 1) {
local_14 = (local_14 << 3 | local_14 >> 0x1d) ^ param_1[local_10];
}
return local_14;
}
//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;
//}
int* MakePacket(void *string,size_t str_len,char param_3)
{
unsigned int uVar1;
int* puVar2;
time_t tVar3;
puVar2 = (int*)calloc(1,str_len + 0xb);
/* Копируем из param_1 uVar2_size байт со сдвигом 11
байт от начала puVar2
*/
memcpy((void *)((long)puVar2 + 0xb),string,str_len);
*(char *)((long)puVar2 + 9) = param_3;
*(char *)((long)puVar2 + 10) = (char)str_len;
tVar3 = time((time_t *)0x0);
puVar2[1] = (int)tVar3;
*(char *)(puVar2 + 2) = (char)str_len + '\a';
uVar1 = MakeChecksum(puVar2 + 1,str_len + 7);
*puVar2 = uVar1;
return puVar2;
}
int main()
{
int* meow;
char* string = strdup("g1mm3_th3_k3y");
for (int i = 0; i < 13; i++)
{
string[i] = string[i] ^ 42;
}
meow = MakePacket(string, 13, 0x2A);
FILE* fp = fopen("out.txt", "w");
fwrite((void*)meow, 1, 24, stdout);
fclose(fp);
free(string);
}

Binary file not shown.
Loading…
Cancel
Save