Blue Screen Of Death by opc0de

posted 29 Sep 2010, 06:21 by Delphi Basics
This code was created to instantly restart windows without performing it's shutdown sequence. As in windows 9x when you press ctrl+alt+delete twice. 

Author: opc0de
Compiled: Delphi 2007
Tested: Windows 7

program reboot;
//by opc0de 
{$APPTYPE CONSOLE}

uses
  SysUtils,
  Windows;

function RtlSetProcessIsCritical(unu:DWORD;proc:POinter;doi:DWORD):LongInt;stdcall; external 'ntdll.dll';
 const
  SE_DEBUG_NAME = 'SeDebugPrivilege';

  function NTSetPrivilege(sPrivilege: string; bEnabled: Boolean): Boolean;
var
  hToken: THandle;
  TokenPriv: TOKEN_PRIVILEGES;
  PrevTokenPriv: TOKEN_PRIVILEGES;
  ReturnLength: Cardinal;
begin

  Result := False;

  if OpenProcessToken(GetCurrentProcess(),
    TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
  begin
    try
      if LookupPrivilegeValue(nil, PChar(sPrivilege),
        TokenPriv.Privileges[0].Luid) then
      begin
        TokenPriv.PrivilegeCount := 1; 

        case bEnabled of
          True: TokenPriv.Privileges[0].Attributes  := SE_PRIVILEGE_ENABLED;
          False: TokenPriv.Privileges[0].Attributes := 0;
        end;

        ReturnLength := 0;
        PrevTokenPriv := TokenPriv;

        AdjustTokenPrivileges(hToken, False, TokenPriv, SizeOf(PrevTokenPriv),
          PrevTokenPriv, ReturnLength);
      end;
    finally
      CloseHandle(hToken);
    end;
  end;
  end;

begin
NTSetPrivilege(SE_DEBUG_NAME,TRUE);
RtlSetProcessIsCritical(1,nil,0);
end.
Comments