// Determine the last two bytes of the MAC address void NsGenMacAddressSignatureForMachine(UCHAR *dst_last_2, UCHAR *src_mac_addr_4) { char machine_name[MAX_SIZE]; BUF *b; UCHAR hash[SHA1_SIZE]; // Validate arguments if (dst_last_2 == NULL || src_mac_addr_4 == NULL) { return; } GetMachineHostName(machine_name, sizeof(machine_name)); Trim(machine_name); StrUpper(machine_name); b = NewBuf(); WriteBuf(b, src_mac_addr_4, 4); WriteBufStr(b, machine_name); HashSha1(hash, b->Buf, b->Size); FreeBuf(b); Copy(dst_last_2, hash, 2); }
// Generate MAC address void NullGenerateMacAddress(UCHAR *mac, UINT id, UINT seq) { UCHAR hash[SHA1_SIZE]; char name[MAX_SIZE]; BUF *b; // Validate arguments if (mac == NULL) { return; } b = NewBuf(); WriteBufInt(b, id); WriteBufInt(b, seq); GetMachineHostName(name, sizeof(name)); #ifdef OS_WIN32 WriteBufInt(b, MsGetCurrentProcessId()); #endif // OS_WIN32 WriteBufStr(b, name); HashSha1(hash, b->Buf, b->Size); FreeBuf(b); Copy(mac, hash, 6); mac[0] = 0x7E; }
// iptables thread void NsIpTablesThread(THREAD *thread, void *param) { IPTABLES_STATE *state; NATIVE_STACK *s; UINT counter = 0; BUF *seed_buf; char exe_name[MAX_PATH]; if (thread == NULL || param == NULL) { return; } s = (NATIVE_STACK *)param; seed_buf = NewBuf(); WriteBuf(seed_buf, s->MacAddress, 6); GetExeName(exe_name, sizeof(exe_name)); WriteBufStr(seed_buf, exe_name); state = StartAddIpTablesEntryForNativeStack(seed_buf->Buf, seed_buf->Size); FreeBuf(seed_buf); if (state == NULL) { NoticeThreadInit(thread); return; } s->IpTablesInitOk = true; NoticeThreadInit(thread); while (true) { UINT wait_interval; if (s->IpTablesHalt) { break; } if (MaintainAddIpTablesEntryForNativeStack(state)) { counter = 0; } counter++; wait_interval = NS_CHECK_IPTABLES_INTERVAL_INIT * counter; wait_interval = MIN(wait_interval, NS_CHECK_IPTABLES_INTERVAL_MAX); //Debug("NsIpTablesThread: wait for %u\n", wait_interval); Wait(s->IpTablesHaltEvent, wait_interval); } EndAddIpTablesEntryForNativeStack(state); }
// ELEMENT を書き出す void WriteElement(BUF *b, ELEMENT *e) { UINT i; // 引数チェック if (b == NULL || e == NULL) { return; } // 名前 WriteBufStr(b, e->name); // 項目の種類 WriteBufInt(b, e->type); // 項目数 WriteBufInt(b, e->num_value); // VALUE for (i = 0;i < e->num_value;i++) { VALUE *v = e->values[i]; WriteValue(b, v, e->type); } }
// Generate a set of dummy IP addresses and mark void GenerateDummyIpAndMark(void *hash_seed, IPTABLES_ENTRY *e, UINT id) { PRAND *p; BUF *b; if (hash_seed == NULL || e == NULL) { return; } b = NewBuf(); WriteBufInt(b, id); WriteBuf(b, hash_seed, SHA1_SIZE); WriteBufStr(b, "20151002"); p = NewPRand(b->Buf, b->Size); FreeBuf(b); GenerateDummyIp(p, &e->DummySrcIp); GenerateDummyIp(p, &e->DummyDestIP); e->DummyMark = GenerateDummyMark(p); FreePRand(p); }
// Output the folder contents (Recursive, binary) void CfgOutputFolderBin(BUF *b, FOLDER *f) { UINT i; // Validate arguments if (b == NULL || f == NULL) { return; } // Folder name WriteBufStr(b, f->Name); // The number of the subfolder WriteBufInt(b, LIST_NUM(f->Folders)); // Subfolder for (i = 0;i < LIST_NUM(f->Folders);i++) { FOLDER *sub = LIST_DATA(f->Folders, i); CfgOutputFolderBin(b, sub); if ((i % 100) == 99) { YieldCpu(); } } // The number of Items WriteBufInt(b, LIST_NUM(f->Items)); // Item for (i = 0;i < LIST_NUM(f->Items);i++) { char *utf8; UINT utf8_size; ITEM *t = LIST_DATA(f->Items, i); // Item Name WriteBufStr(b, t->Name); // Type WriteBufInt(b, t->Type); switch (t->Type) { case ITEM_TYPE_INT: // Integer WriteBufInt(b, *((UINT *)t->Buf)); break; case ITEM_TYPE_INT64: // 64-bit integer WriteBufInt64(b, *((UINT64 *)t->Buf)); break; case ITEM_TYPE_BYTE: // Data size WriteBufInt(b, t->size); // Data WriteBuf(b, t->Buf, t->size); break; case ITEM_TYPE_STRING: // String utf8_size = CalcUniToUtf8((wchar_t *)t->Buf) + 1; utf8 = ZeroMalloc(utf8_size); UniToUtf8(utf8, utf8_size, (wchar_t *)t->Buf); WriteBufInt(b, StrLen(utf8)); WriteBuf(b, utf8, StrLen(utf8)); Free(utf8); break; case ITEM_TYPE_BOOL: // Boolean type if (*((bool *)t->Buf) == false) { WriteBufInt(b, 0); } else { WriteBufInt(b, 1); } break; } } }