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

Can I kill the judge service? #539

Open
zhanhb opened this issue Jan 2, 2018 · 11 comments
Open

Can I kill the judge service? #539

zhanhb opened this issue Jan 2, 2018 · 11 comments

Comments

@zhanhb
Copy link

zhanhb commented Jan 2, 2018

#include <stdio.h>
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>
int main() {
    HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    PROCESSENTRY32 pe = {0};
    pe.dwSize = sizeof (PROCESSENTRY32);
    DWORD pid = GetCurrentProcessId();
    if (Process32First(h, &pe)) {
        do {
            if (pe.th32ProcessID == pid) {
                printf("PID: %i; PPID: %i\n", pid, pe.th32ParentProcessID);
                HANDLE h = OpenProcess(PROCESS_TERMINATE, 0, pe.th32ParentProcessID);
                if (h) {
                    TerminateProcess(h, 0);
                    CloseHandle(h);
                }
            }
        } while (Process32Next(h, &pe));
    }
    CloseHandle(h);
}
@NikolayIT
Copy link
Owner

You can try :))

@zhanhb
Copy link
Author

zhanhb commented Jan 2, 2018

I'm not sure if I succeed to do it. But I only see
This submission is being processed at the moment... Please wait.

@zhanhb
Copy link
Author

zhanhb commented Jan 3, 2018

It seems I succeed to kill the judge client.
http://bgcoder.com/Submissions

@NikolayIT
Copy link
Owner

Good job! Can you provide us with a fix? :)

@zhanhb
Copy link
Author

zhanhb commented Jan 3, 2018

Not yet, I'm trying to find a solution fix this too.

@zhanhb
Copy link
Author

zhanhb commented Jan 23, 2018

I found one solution now.

ScopedHandle token;
CreateRestrictedToken(USER_LIMITED, INTEGRITY_LEVEL_LOW, PRIMARY, true, &token);
STARTUPINFO sa = {sizeof(sa)};
sa.lpDesktop = TEXT("Winsta0\\default"); // this line is optional if you are not running in windows service
CreateProcessAsUser(token.Get(), lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, &sa, lpProcessInformation);
// job

https://chromium.googlesource.com/chromium/src.git/+/66.0.3329.3/sandbox/win/src/restricted_token_utils.cc#54

@zhanhb
Copy link
Author

zhanhb commented Jan 23, 2018

Without setting lpDesktop of startup info, you will get incorrect when running java in windows service.

@NikolayIT
Copy link
Owner

What changes do you suggest here:

@zhanhb
Copy link
Author

zhanhb commented Jan 23, 2018

if (!NativeMethods.CreateRestrictedToken(
        processToken,
        SANDBOX_INERT | DISABLE_MAX_PRIVILEGE,
        ?, // Disable SID
        ?, // all sids in the token except Users("S-1-5-32-545"), Everyone("S-1-1-0"), Interactive("S-1-5-4")
        0, // Delete privilege
        null, // these two are ignored if DISABLE_MAX_PRIVILEGE is specified
        4, // Restricted SID
        ?, // Users, Everyone, restrict code("S-1-5-12"), login sid
        out restrictedToken))

if (!NativeMethods.CreateRestrictedToken(
processToken,
CreateRestrictedTokenFlags.SANDBOX_INERT, // TODO: DISABLE_MAX_PRIVILEGE ??
0, // Disable SID
null,
0, // Delete privilege
null,
0, // Restricted SID
null,
out restrictedToken))

@KonstantinBobrovski
Copy link

Hello, I think simple System.Diagnostics.Process.GetCurrentProcess().Kill(); in C# could kill Judje,but i am good man and i will not try this. (but what you will do if i succses?)

@KonstantinBobrovski
Copy link

You can not allow Process.Kill method it maybe will help.And this is working.

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

No branches or pull requests

3 participants