Post Pacific

Post Pacific (https://postpacific.loc-online.com/index.php)
-   Темы без сохранившегося раздела (https://postpacific.loc-online.com/forumdisplay.php?f=10001)
-   -   [Share] server side html exploit fix, cloning char fix (https://postpacific.loc-online.com/showthread.php?t=2152)

tontor 09.10.2005 06:50

[Share] server side html exploit fix, cloning char fix
 
[edit] be sure to look for updates later on in the thread [/edit]
Heres my solution for html exploits, I'll explain how it works. Each time a client requests a html the server will parse the requested html for valid commands, crc them, and store them in a vector referenced by this characters accountid. each call that handles a bypass or link cmd has been hooked, so every bypass or link cmd the client sends to the server, now gets, crcd and checked against the users table in the vector. If the cmd crc matches one that was previously stored for this user, the cmd is verified and the user is permitted to pass the cmd, when it fails to match the cmd and account are is logged to the l2server console and error log files as a possible exploit attempt. Every time a user successfully completes a cmd or enterworld is called (if they relog), their table is cleared. Link is handled the same way, only on failure it will retrieve the file linkerr.htm displaying it to the user, just put an access denied msg or whatever you please here.


The vector size supports a default of 200,000 accounts, and a cmdlist of no more then 40 commands per html. At allocation time this uses ~30mb of memory, should you exceed 200,000 accounts it will double its size, until it can accomodate that high of account id(this will be buggy and cause problems in most cases cause of threading). So long as your html does not have more then 40cmds or a teleport list larger then 40 locations will work fine, and if you exceed that limit of 40, all cmds past the 40th will be ignored, and logged as an exploit.


Now that said there are a few things to explain about the effects this can cause.

First off, the method most versions of l2walker (maybe other bot clients also) handle htmls differs from ncsofts client, a side effect of this is that a majority of l2walker users will be logged as exploiters every time they access an npc, and denied access to use them. (not a bad side effect). If you see alot of failed teleport requests, warehouse withdraws, recipe crafting, from a certain account id, they are using a 3rd party client such as l2walker.

Second, didn't feel the need to handle in-game BBS since i don't think anyone ever uses it because it causes a lot of stability problems. So all _bbs commands logged as html exploit can be ignored, its simply an unhandled call.

Next, there appears to be a a few htmls for quests and such where the htmls include a link command that has extra spaces between "link nameof.htm", if you see alot of warnings for a html similar to something like name_q017_9823.htm, use grep or some other regexp program on all the html files in your html folder and locate the html that is calling link for this, and check it, it will have an extra space or something similar to this that is causing it to be reported incorrectly, and denying users access. (powergrep for windows is what i use).

(the following have link followed by 2 spaces and need to be corrected)
terry_q0213_22.htm
terry_q0213_21.htm
terry_q0213_18.htm
terry_q0213_08.htm
terry_q0213_06.htm
blacksmith_pushkin_q0218_07.htm

(the following have a space before the link cmd)
charkeren_q0412_01.htm

This patch should work for all, or most C1, C2, and C3 servers. I've tested it with c1 and c3 but not c2. Make a backup of your original l2server.exe, extract patch.exe and patch.dll into a folder with l2server.exe and run patch.exe once, after this you may discard patch.exe. l2server.exe will now force load of patch.dll opening a new console as you run it, displaying a list of calls that were hooked. Be sure that all of these are patched successfully, and if any fail then your l2server already has a modification at this address and wont be applied, most likely causing crashes and who knows what else. If you used my link+tp patch I posted on the forum awhile ago i suggest you use n l2server.exe without it, if you don't i believe link and teleport patches will fail but may still run fine.


Also this patch fixes the issue with people using l2walker to clone chars (livid mentioned something about there was a duping method using this), instead of just closing the user socket this calls leaveworld also making this method not work any longer.

I believe that covers about everything.
I've attached the patch and some fixed htmls.

Enishi 09.10.2005 07:12

Simply amazing.

Livid 09.10.2005 07:28

O_O

Juiced 09.10.2005 07:33

Scan type: Realtime Protection Scan
Event: Virus Found!
Virus name: W32.Small.gen
File: C:\DOCUME~1\CaDuSiMs\CONFIG~1\Temp\Rar$EXxx.xx5\pa tch.exe
Location: Quarantine
Computer: CADU
User: CaDuSiMs
Action taken: Clean failed : Quarantine succeeded : Access denied
Date found: Sun Oct 09 04:33:38 2005

SoaPy 09.10.2005 07:34

Good Work Tontor, tnx

toolpunk 09.10.2005 07:39

lol you got a virus XD
W32.Small.gen...
detected by norton antivirus corp...
so dont tell me im talking shit.
its true. you should scan your pc for viruses ;)
btw i dont say this happened on purpose but i wanted to warn everyone and especially you to scan your system for viruses.
so its rather a good advice than criticism...

edit: damn juiced was faster XD

tontor 09.10.2005 07:48

Quote:

Originally Posted by Juiced
Scan type: Realtime Protection Scan
Event: Virus Found!
Virus name: W32.Small.gen
File: C:\DOCUME~1\CaDuSiMs\CONFIG~1\Temp\Rar$EXxx.xx5\pa tch.exe
Location: Quarantine
Computer: CADU
User: CaDuSiMs
Action taken: Clean failed : Quarantine succeeded : Access denied
Date found: Sun Oct 09 04:33:38 2005

Quote:

Originally Posted by toolpunk
lol you got a virus XD
W32.Small.gen...
detected by norton antivirus corp...
so dont tell me im talking shit.
its true. you should scan your pc for viruses ;)
btw i dont say this happened on purpose but i wanted to warn everyone and especially you to scan your system for viruses.
so its rather a good advice than criticism...

edit: damn juiced was faster XD

This is not a virus, but a false positive by some virus scanners. The full source to patch.exe is below. Review and compile it yourself if you wish.

Code:

;Static DLL Injection for MASM by Aphex
;http://www.iamaphex.cjb.net
;[email protected]
;This uses code by Yodah and Freddy K

;What this does: It forces a PE to load a DLL everytime it is ran by
;patching the actual file. No other loaders or memory injectors are needed.

;How it does this: It opens the PE file, adds a section to the end of the file,
;alters the entry point to execute this section first. Then the new code loads
;a dll and jumps back to the original entry point where it runs as normal. ;)

;NOTE: you must add this linker option "/SECTION:.text,RWX"
;ml.exe /coff patch.asm /link /SECTION:.text,RWX /SUBSYSTEM:WINDOWS /OPT:NOREF
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

SEH_STRUCT struct
  OrgEsp dword 0
  OrgEbp dword 0
  SaveEip dword 0
SEH_STRUCT ends

.data
;-------> Path to EXE to be patched with DLL <-------
szTarget byte 'L2Server.exe', 0

.data?
dwFile dword ?
dwSize dword ?
dwBytes dword ?
dwImage dword ?
dwBuffer dword ?
dwHeader dword ?
dwLength dword ?
dwSections dword ?

.data
errmsg        db        'failed to open l2server.exe',0
sucmsg        db        'patching l2server.exe succeeded',0
titlemsg db        'beepbeepboop',0

.code
EntryPoint:
jmp PatchEnd
PatchBegin:
jmp SkipData
szName byte '.PATCH', 2 dup (0)
szLoadLibrary byte 'LoadLibraryA', 0
;-------> Path to DLL to be patched into EXE <-------
szDll byte 'patch.dll', 0
SEH SEH_STRUCT <>
_LoadLibrary dword 0
dwKernelBase dword 0
dwEntryPoint dword 0
_DllOff dword 0
SkipData:
assume fs:NOTHING
pushad
call Root
Root:
pop ebp
sub ebp, offset Root
push dword ptr [esp + 20h]
call Base
or eax, eax
jz Return
mov [ebp + dwKernelBase], eax
lea eax, [ebp + offset szLoadLibrary]
push eax
push [ebp + dwKernelBase]
call Address
or eax, eax
jz Return
mov [ebp + _LoadLibrary], eax
lea eax, [ebp + offset szDll]
push eax
call [ebp + _LoadLibrary]
mov [ebp + offset _DllOff], eax
Return:
mov eax, [ebp + dwEntryPoint]
mov [esp + 1ch], eax
popad
jmp eax
Base:
mov edi, [esp + 4]
lea eax, [ebp + offset SehHandler]
push eax
push dword ptr fs:[0]
lea eax, [ebp + offset SEH]
assume eax:ptr SEH_STRUCT
mov [eax].OrgEsp, esp
mov [eax].OrgEbp, ebp
lea ebx, [ebp + offset Continue]
mov [eax].SaveEip, ebx
mov fs:[0], esp
assume eax:NOTHING
and edi, 0FFFF0000h
.while TRUE
  .if word ptr [edi] == IMAGE_DOS_SIGNATURE
    mov esi, edi
    add esi, [esi + 03Ch]
    .if dword ptr [esi] == IMAGE_NT_SIGNATURE
      .break
    .endif
  .endif
Continue:
  sub edi, 010000h
  .if edi < 070000000h
    mov edi, 0BFF70000h
    .break
  .endif
.endw
xchg eax, edi
pop dword ptr fs:[0]
add esp, 4
ret 4
Address:
lea eax, [ebp + offset SehHandler]
push eax
push dword ptr fs:[0]
lea eax, [ebp + offset SEH]
assume eax:ptr SEH_STRUCT
mov [eax].OrgEsp, esp
mov [eax].OrgEbp, ebp
lea ebx, [ebp + offset Continue]
mov [eax].SaveEip, ebx
mov fs:[0], esp
assume eax:NOTHING
mov esi, [esp + 0ch]
.if word ptr [esi] != IMAGE_DOS_SIGNATURE
  jmp Halt
.endif
add esi, [esi + 03Ch]
.if dword ptr [esi] != IMAGE_NT_SIGNATURE
  jmp Halt
.endif
mov edi, [esp + 10h]
mov ecx, 150
xor al, al
repnz scasb
mov ecx, edi
sub ecx, [esp + 10h]
mov edx, [esi + 078h]
add edx, [esp + 0ch]
assume edx:ptr IMAGE_EXPORT_DIRECTORY
mov ebx, [edx].AddressOfNames
add ebx, [esp + 0ch]
xor eax, eax
.repeat
  mov edi, [ebx]
  add edi, [esp + 0ch]
  mov esi, [esp + 10h]
  push ecx
  repz cmpsb
  .if zero?
    add esp, 4
    .break
  .endif
  pop ecx
  add ebx, 4
  inc eax
.until eax == [edx].NumberOfNames
.if eax == [edx].NumberOfNames
  jmp Halt
.endif
mov esi, [edx].AddressOfNameOrdinals
add esi, [esp + 0ch]
push edx
mov ebx, 2
xor edx, edx
mul ebx
pop edx
add eax, esi
xor ecx, ecx
mov word ptr cx, [eax]
mov edi, [edx].AddressOfFunctions
xor edx, edx
mov ebx, 4
mov eax, ecx
mul ebx
add eax, [esp + 0ch]
add eax, edi
mov eax, [eax]
add eax, [esp + 0ch]
jmp Exit
assume edx:nothing
Halt:
xor eax, eax
Exit:
pop dword ptr fs:[0]
add esp, 4
ret 8
SehHandler proc c pExcept:dword, pFrame:dword, pContext:dword, pDispatch:dword
mov eax, pContext
assume eax:ptr CONTEXT
push SEH.SaveEip
pop [eax].regEip
push SEH.OrgEsp
pop [eax].regEsp
push SEH.OrgEbp
pop [eax].regEbp
mov eax, ExceptionContinueExecution
ret
SehHandler endp
PatchEnd:
mov eax, offset PatchEnd
sub eax, offset PatchBegin
mov dwLength, eax
invoke CreateFile, offset szTarget, GENERIC_READ or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0
.if eax == INVALID_HANDLE_VALUE
  invoke MessageBox, NULL,addr errmsg,addr titlemsg,MB_OK
  invoke ExitProcess, 0
.endif
mov dwFile, eax
invoke GetFileSize, dwFile, 0
mov dwSize, eax
add eax, 2000h
invoke GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, eax
mov dwBuffer, eax
invoke ReadFile, dwFile, dwBuffer, dwSize, offset dwBytes, 0
mov esi, dwBuffer
add esi, 03ch
mov eax, dword ptr [esi]
mov dwHeader, eax
sub eax, 03ch
add esi, eax
assume esi:ptr IMAGE_NT_HEADERS
mov ax, [esi].FileHeader.NumberOfSections
mov dwSections, eax
inc [esi].FileHeader.NumberOfSections
mov eax, [esi].OptionalHeader.AddressOfEntryPoint
add eax, [esi].OptionalHeader.ImageBase
mov dwEntryPoint, eax
mov eax, [esi].OptionalHeader.SizeOfImage
mov dwImage, eax
add [esi].OptionalHeader.SizeOfImage, 1000h
mov [esi].OptionalHeader.AddressOfEntryPoint, eax
assume esi:NOTHING
mov esi, dwBuffer
add esi, dwHeader
add esi, 0f8h
assume esi:ptr IMAGE_SECTION_HEADER
mov eax, 0E0000060h
mov [esi].Characteristics, eax
mov eax, 28h
mov ecx, dwSections
imul ecx
add esi, eax
mov eax, dword ptr [szName]
mov dword ptr [esi].Name1, eax
mov eax, dword ptr[szName+4]
mov dword ptr [esi].Name1+4, eax
mov eax, 1000h
mov [esi].Misc.VirtualSize, eax
mov eax, dwImage
mov [esi].VirtualAddress, eax
mov eax, dwLength
mov [esi].SizeOfRawData, eax
mov eax, dwSize
mov [esi].PointerToRawData, eax
mov eax, 0E0000020h
mov [esi].Characteristics, eax
assume esi:NOTHING
mov edi, dwBuffer
add edi, dwSize
lea eax, PatchBegin
xchg esi, eax
mov ecx, dwLength
rep movsb
invoke SetFilePointer, dwFile, 0, 0, FILE_BEGIN
mov eax, dwSize
add eax, dwLength
invoke  WriteFile, dwFile, dwBuffer, eax, offset dwBytes, 0
invoke CloseHandle, dwFile
invoke GlobalFree, dwBuffer
invoke MessageBox, NULL,addr sucmsg,addr titlemsg,MB_OK
invoke ExitProcess, 0
end EntryPoint


flakka 09.10.2005 08:22

Nice post, tontor. :)

And second, you guys need to seriously get a better AV scanner. Norton sucks - plain and simple. The only good thing it has is the sandbox feature, and even with that, it can't scan anything for crap. I just scanned it with F-Prot, and nothing came back. No false positives, and no virus. It's clean like tontor said.

So please, please get rid of anything Symantec/Norton related off your PCs. :P Worst piece of software, ever.

Sorry for hijacking the thread, but I just can't stand Norton. And people do need to know that there's better alternatives out there that are less resource hungry and have better scanning engines.

demon 09.10.2005 08:32

what about f-secure ^^ sucks too ?

OnlyOne 09.10.2005 08:45

well scanned with kaspersky and nothing found :lol:

demon 09.10.2005 09:10

except bbs all others are hack attempt ? or space error.

top-gear 09.10.2005 10:32

I think it's a great share if it acrually works. The problem is that it may leave other kind of "doors" open. or not...?

toolpunk 09.10.2005 11:16

f-secure?! LOL... sorry but that isnt any better in my opinion...
btw im runnin on windows server 2k3 means i cant use just a virus prog...
needs to be a corporate version since antivirus companies wanna earn money ;)
so i ended up using noton corp. it works just fine and is secure :)

hamidouch 09.10.2005 11:19

yes demon it is,
tontor fukin nice u fixed it ^^
no more+20 cmd problem

Phantom2005 09.10.2005 11:30

thx m8! this is a really great share :)

midnight 09.10.2005 12:04

Quote:

Originally Posted by demon
except bbs all others are hack attempt ? or space error.

what should i do to make this window appear?

Eliot 09.10.2005 12:32

tontor, i owe You one. I swear if i ever meet You, You will be drunk as hell :P Im buying :) (If You are really Japanese this may actually happen so beware :P)

Not only because You shared the fix, You shared a lot more, You showed us the way how to attach a external program to l2server. This way we can manage to archieve something we never thought about before. Macros, Reccomend, CP, Recipe Books. It's possible now ! We just need a bloody good coder :)

blaher 09.10.2005 14:30

hmm ? ;/

Silentz0r 09.10.2005 15:24

Fixed. ty.

horyfilipe 09.10.2005 15:59

thank you and congratulations!

horyfilipe 09.10.2005 16:25

Hmm... world announce disappeared and when i tried //gmspeed 5 server freezed.. any suggestion?

link and tp patch failed but i think it has nothing to do with that..

Sauron 09.10.2005 16:38

Quote:

Originally Posted by Livid
O_O


horyfilipe 09.10.2005 16:51

Actualy I thought it was //gmspeed freezing, but it isnt.. someway the server is freezing and it doesnt crash, have to kill.. any idea?

astranger 09.10.2005 17:01

good job and thanks for sharing

LDragonL 09.10.2005 17:06

This is a very very nice tool !
Thanx a lot man !

tontor 09.10.2005 19:00

Quote:

Originally Posted by Eliot
tontor, i owe You one. I swear if i ever meet You, You will be drunk as hell :P Im buying :) (If You are really Japanese this may actually happen so beware :P)

Not only because You shared the fix, You shared a lot more, You showed us the way how to attach a external program to l2server. This way we can manage to archieve something we never thought about before. Macros, Reccomend, CP, Recipe Books. It's possible now ! We just need a bloody good coder :)


I'm not really from japan and i don't drink :). I don't mind sharing these parts of the things I've done, the primary goal was to provide others with a good solution for html exploit problem. If i hadn't added so many other fixes to the source code already i might of shared that as well, but there are some things i don't wish to make public :).

Quote:

Originally Posted by horyfilipe
Actualy I thought it was //gmspeed freezing, but it isnt.. someway the server is freezing and it doesnt crash, have to kill.. any idea?

Try using an exe without my link and teleport fix. I cant really say what the effects are if those fail, but very likely that it could cause problems.


Quote:

Originally Posted by demon
except bbs all others are hack attempt ? or space error.

ignore _bbs, and account id 25662 looks more like someone using walker then attempting html exploits, because of the commands being used are common, multisell, warehouse, and from the same accountid. things like this (below) are more commonly exploit attempts. but exploit can be done with any command you just need to see what other actions the user has performed and make a decision based on their actions.

10/09/2005 07:59:xx.xx3, WARNING: Possible exploit attempt ACCID:9175 CMD:[bypass -h menu_select?ask=333&reply=15].

horyfilipe 09.10.2005 19:11

would you be so kind to share urs? all i could find are patched..

about linkerr.htm, when is it called? is it supposed to show everytime client tries htm hacks? cause i tried and nothing displayed on client, but server warnings

tontor 09.10.2005 19:28

Quote:

Originally Posted by horyfilipe
would you be so kind to share urs? all i could find are patched..

about linkerr.htm, when is it called? is it supposed to show everytime client tries htm hacks? cause i tried and nothing displayed on client, but server warnings

ill post some code to revert changes made by that patch later, and whenever someone uses a link action that is not verified, is the only time linkerr.htm will be displayed try a help.htm exploit that uses a link balab.htm cmd and you will be shown the msg.

Livid 09.10.2005 19:39

Can you post changes needed, not patcher? My server is heavily modded, and it seem to conflict with your patcher <_<
Like, few dlls attatched, few sections resized, new added etc.
And taking info from ur self-modyfiing attachement to clean server file is something I don't want to do.

Domzelan 09.10.2005 19:39

tontor - I'll pach my server, but first 2 lines - failed - is html fix working?:) i cant chek it :(

zabbix 09.10.2005 19:56

hehe

Quote:

Server Up Time Sun Oct 09 21:10:00 2005

Current Time : Sun Oct 09 22:12:14 2005

Elapsed Time : 0 days 1 hours 2 minutes 14 seconds
IOBufferPool - 38690

[(1040) 2005/10/09 22:12:14]: =======================
an Access Violation in module ntdll.dll at 001b:77f4696b.
start at 2005/10/9 21:09:57
Write to location 00610070 caused an access violation.

Registers:
EAX=208521a0 CS=001b EIP=77f4696b EFLGS=00010246
EBX=20850178 SS=0023 ESP=70a8f5ec EBP=70a8f6a0
ECX=208521a0 DS=0023 ESI=20852198 FS=003b
EDX=00610070 ES=0023 EDI=20850000 GS=0000
Bytes at CS:EIP:
89 02 89 41 04 56 8b

Domzelan 09.10.2005 20:05

What is it?

LDragonL 09.10.2005 21:10

My l2server file gave an error too when i used the patcher,
but then i decided to start from the beginning and change the port, safe enchant etc. all over.
I can tell you it's worth it, this is a great tool.
I didn't test what happens without a protected ai.obj, does it still blocks the exploit ?
I hope someone can tell me cos i'm really curious.

Greetz

tontor 09.10.2005 23:34

Quote:

Originally Posted by Livid
Can you post changes needed, not patcher? My server is heavily modded, and it seem to conflict with your patcher <_<
Like, few dlls attatched, few sections resized, new added etc.
And taking info from ur self-modyfiing attachement to clean server file is something I don't want to do.

you'll have to make a new section manually or add a call to loadmodule similar to the method in the source i provided, then see what all fails to patch and check the offsets against your original to see what changed. the patches in l2server made by the dll insert dynamic addresses, so there's not much i can do except tell you to try to load the dll with same method i have in your own sections and return to your own code.


To others sorry ill reply later about offsets to change for reverting link+tp fixes and reply/comment to others.

Quote:

Originally Posted by LDragonL
My l2server file gave an error too when i used the patcher,
but then i decided to start from the beginning and change the port, safe enchant etc. all over.
I can tell you it's worth it, this is a great tool.
I didn't test what happens without a protected ai.obj, does it still blocks the exploit ?
I hope someone can tell me cos i'm really curious.

Greetz

yes this would block all exploit attempts using an unchanged ai.obj

horyfilipe 10.10.2005 03:35

Ive got a clean l2server, so that all patches went successfuly.. after 1 hour running (more stable than before), server freezed and last msgs was:
http://www.horyu.com.br/img/uploads/7f0ee0c182.jpg

CubAfull 10.10.2005 04:23

O.O nice tool !
Thanx a lot man !

O.o fuck.... norton....

LDragonL 10.10.2005 05:24

Damn those sick mf's are still able to crash the server :(

Sauron 10.10.2005 05:28

tontor check pm

srh 10.10.2005 07:24

nice tool tontor!

btw, in todo list (if any?;) ):
change packets about players, to hide HP/MP count, set it to 0?
hide what armor on head (client not need this, but bots ...)

kok 10.10.2005 08:34

Norton Antivirus - Big Sux. Use NOD32.

Very nice tool tontor!


All times are GMT. The time now is 16:14.