mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:48:14 +00:00
LookupServer: Retry with 0x20 randomization turned off on EREFUSED
Apparently some authoritative servers don't handle 0x20 randomization well and may send EREFUSED. Retry with randomization turned off then. Reference: https://github.com/dns-violations/dns-violations/blob/master/2017/DVE-2017-0006.md More work towards #10.
This commit is contained in:
parent
00be9b33b1
commit
a9ec2225a5
6 changed files with 48 additions and 11 deletions
|
@ -13,22 +13,24 @@ DNSRequest::DNSRequest()
|
|||
{
|
||||
}
|
||||
|
||||
void DNSRequest::add_question(const String& name, u16 record_type)
|
||||
void DNSRequest::add_question(const String& name, u16 record_type, ShouldRandomizeCase should_randomize_case)
|
||||
{
|
||||
ASSERT(m_questions.size() <= UINT16_MAX);
|
||||
|
||||
if (name.is_empty())
|
||||
return;
|
||||
|
||||
// Randomize the 0x20 bit in every ASCII character.
|
||||
StringBuilder builder;
|
||||
for (size_t i = 0; i < name.length(); ++i) {
|
||||
u8 ch = name[i];
|
||||
if (isalpha(ch)) {
|
||||
if (arc4random_uniform(2))
|
||||
ch |= 0x20;
|
||||
else
|
||||
ch &= ~0x20;
|
||||
if (should_randomize_case == ShouldRandomizeCase::Yes) {
|
||||
// Randomize the 0x20 bit in every ASCII character.
|
||||
if (isalpha(ch)) {
|
||||
if (arc4random_uniform(2))
|
||||
ch |= 0x20;
|
||||
else
|
||||
ch &= ~0x20;
|
||||
}
|
||||
}
|
||||
builder.append(ch);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue