Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (Re)HLDS exploit (Can't use keys or values with a ") #595

Merged
merged 1 commit into from Apr 1, 2018

Conversation

IgnacioFDM
Copy link
Contributor

Assume two clients connect with the following string

connect 48 12345678 \prot\2\unique\-1\raw\261578371d95a424925835ca44f82811 \cl_lw\1\cl_lc\1\*hltv\1\rate\10000\cl_updaterate\20\hspecs\0\hslots\0\hdelay\30\name\test"

Name will be parsed as test"

Then in SV_CheckForDuplicateNames, Info_SetValueForKey will fail because of the quotes, and an infinite loop will occur.

I also added a check for \. Altough it's technically impossible to appear, it never hurts to be extra careful with this kind of client input.

TODO (by others, sorry, really busy atm):

  • Fix COM_Parse so that you can't inject quote marks. Other exploits may currently exist that also rely on this bug.

Assume two clients connect with the following string

```connect 48 12345678  \prot\2\unique\-1\raw\261578371d95a424925835ca44f82811   \cl_lw\1\cl_lc\1\*hltv\1\rate\10000\cl_updaterate\20\hspecs\0\hslots\0\hdelay\30\name\test"```

Name will be parsed as ```test"```

Then in ```SV_CheckForDuplicateNames```, ```Info_SetValueForKey``` will fail because of the quotes, and an infinite loop will occur.

I also added a check for ```\```, altough it's technically impossible to appear, it never hurts to be extra careful with this kind of client input.

TODO (by others sorry, really busy atm):
- Fix ```COM_Parse``` so that you can't inject quote marks. Other exploits may currently exist that also rely on this bug.
@In-line
Copy link
Collaborator

In-line commented Apr 1, 2018

Merging for now, because bug was disclosed. Btw I think there are better ways to fix this

@In-line In-line merged commit 19e3a5d into dreamstalker:master Apr 1, 2018
@IgnacioFDM
Copy link
Contributor Author

How do you think it should be fixed?

@WPMGPRoSToTeMa
Copy link
Contributor

Maybe it should be validated inside Host_SetInfo_f or Info_SetValueForKey.

@IgnacioFDM
Copy link
Contributor Author

IgnacioFDM commented Apr 1, 2018

@WPMGPRoSToTeMa The existing validation in Info_SetValueForKey (actually Info_SetValueForStarKey) is what causes the infinite loop (since it returns instead of actually setting the new key, and thus causing an infinite loop when trying to remove duplicate names).

IMO the proper way to fix this is in COM_Parse (and related functions). I would still leave the current checks for extra safety.

@WPMGPRoSToTeMa
Copy link
Contributor

WPMGPRoSToTeMa commented Apr 1, 2018

@IgnacioFDM validation inside SV_CheckUserInfo is enough, code in SV_ExtractFromUserInfo is redundant. Validation for backslash is also redundant, it is validated here

i = Q_strlen(userinfo);
if (i <= 4 || Q_strstr(userinfo, "\\\\") || userinfo[i - 1] == '\\')
{
SV_RejectConnection(adr, "Unknown HLTV client type.\n");
return 0;
}
only last value can possibly contain backslash.

@In-line
Copy link
Collaborator

In-line commented Apr 1, 2018

@WPMGPRoSToTeMa We can add "" check in SV_ReplaceSpecialCharactersInName

@WPMGPRoSToTeMa
Copy link
Contributor

The best way I think is to fix Info_IsValid function to also check quotes in keys/values.

@In-line
Copy link
Collaborator

In-line commented Apr 1, 2018

@WPMGPRoSToTeMa And I think we should return boolean value indicating success or failure for Info_SetValueForKey.

@WPMGPRoSToTeMa
Copy link
Contributor

@In-line how do you want to use it in existing code?

@In-line
Copy link
Collaborator

In-line commented Apr 1, 2018

@WPMGPRoSToTeMa It's good for future usage.

@WPMGPRoSToTeMa
Copy link
Contributor

@In-line well maybe for proper error handling.

@WPMGPRoSToTeMa
Copy link
Contributor

WPMGPRoSToTeMa commented Apr 1, 2018

Looks like checks for double backslash and for backslash at the end are also redundant because Info_IsValid already checks for empty keys and values. Double backslash is empty key + empty value or empty value + empty key, backslash at the end is empty key.

i = Q_strlen(userinfo);
if (i <= 4 || Q_strstr(userinfo, "\\\\") || userinfo[i - 1] == '\\')
{
SV_RejectConnection(adr, "Unknown HLTV client type.\n");
return 0;
}

It is also interesting why quotes are prohibited, maybe because you can't input them into your userinfo via setinfo (and also initial userinfo, which is contained in connect packet, is enclosed by quotes).

@IgnacioFDM
Copy link
Contributor Author

Remember that although I showed the exploit during connection, a user can change name (and other userinfo) while playing. Info_IsValid is not called in such case.

@WPMGPRoSToTeMa
Copy link
Contributor

WPMGPRoSToTeMa commented Apr 1, 2018

@IgnacioFDM

a user can change name (and other userinfo) while playing. Info_IsValid is not called in such case.

Info_SetValueForKey behaves well for in-game cases, because userinfo just isn't affected.
Let me explain:
Somebody changes his name via name "some\name", so the client sends to the server setinfo "name" "some\name".
The server receives that command and calls Host_SetInfo_f which calls Info_SetValueForKey and it just returns without changing nothing, like setinfo wasn't received by the server.

You can check it yourself by typing cmd setinfo name nick\name or cmd setinfo name nick"name.

@In-line
Copy link
Collaborator

In-line commented Apr 1, 2018

@WPMGPRoSToTeMa Info_IsValid is horrible

@WPMGPRoSToTeMa
Copy link
Contributor

@In-line what do you mean?

@In-line
Copy link
Collaborator

In-line commented Apr 1, 2018

@WPMGPRoSToTeMa I just wanted to share my pain with somebody (⌣_⌣”)

@In-line
Copy link
Collaborator

In-line commented Apr 1, 2018

@IgnacioFDM @WPMGPRoSToTeMa Please review #596

@WPMGPRoSToTeMa
Copy link
Contributor

COM_Parse is also an interesting thing, because idk where single " is applicable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants