【问题标题】:Temporarily disable impersonation in ASP在 ASP 中暂时禁用模拟
【发布时间】:2014-06-18 17:31:35
【问题描述】:

我正在编写一个内部网系统,该系统通过使用ADODB.Stream 的脚本将文件本地写入网络服务器。问题是,它使用记录的 Windows/AD 用户帐户来执行此操作,因为默认情况下在 IIS 中激活了模拟 - 而我实际上大部分时间都需要激活它。由于我不想将网络服务器的写入权限授予需要使用该系统的任何人,因此我需要暂时将会话“取消模拟”回“IUSR”帐户。

我怎么能这样做?首选在经典 ASP 中,因为整个网站都在其中编码,但也可以是 ASP.net (C#) 中的内容。

我在一家大公司工作,我对 IIS 控制面板/服务器机器的访问有点受限(需要与其他部门打交道)。而且我也无法安装任何自定义模块或 DLL。

【问题讨论】:

标签: c# asp.net iis asp-classic impersonation


【解决方案1】:

过去,我使用Msxml2.ServerXMLHTTP 进行服务器端调用,该调用使用 HTTP 授权标头切换模拟上下文。这使我可以使用与网站运行环境不同的上下文来创建文件。

Sub ExecuteContext(url, data, user, password)
  Dim http

  Set http = Server.CreateObject("Msxml2.ServerXMLHTTP")
  Response.CharSet = "utf-8"

  Call http.open("POST", url, False, user, password)

  'Called using Basic Authentication (not as secure as Windows Authenticated by should be adequate)
  Call http.setRequestHeader("Authorization", "Basic " & Base64Encode(user & ":" & password))
  Call http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
  Call http.send(data)
End Sub

'Supporting functions to do the Base64 encoded Authorization header.
Function Base64Encode(inData)
  'ripped from: 
  'http://www.pstruh.cz/tips/detpg_Base64Encode.htm
  'rfc1521
  '2001 Antonin Foller, PSTRUH Software, http://pstruh.cz
  Const Base64 = _
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  Dim sOut, I

  'For each group of 3 bytes
  For I = 1 To Len(inData) Step 3
    Dim nGroup, pOut

    'Create one long from this 3 bytes.
    nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _
      &H100 * MyASC(Mid(inData, I + 1, 1)) + _
      MyASC(Mid(inData, I + 2, 1))

    'Oct splits the long To 8 groups with 3 bits
    nGroup = Oct(nGroup)

    'Add leading zeros
    nGroup = String(8 - Len(nGroup), "0") & nGroup

    'Convert To base64
    pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _
      Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _
      Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _
      Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1)

    'Add the part To OutPut string
    sOut = sOut + pOut

  Next
  Select Case Len(inData) Mod 3
    Case 1: '8 bit final
      sOut = Left(sOut, Len(sOut) - 2) + "=="
    Case 2: '16 bit final
      sOut = Left(sOut, Len(sOut) - 1) + "="
  End Select
  Base64Encode = sOut
End Function

Function MyASC(OneChar)
  If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
End Function

这种方法非常灵活,在我的实现中,我使用它通过 POST 来更改同一页面中的上下文,但使用不同的data

【讨论】:

  • 我自己已经找到了答案,但我赞成这个,因为它是一种非常有趣的技术。
【解决方案2】:

我以不同的方式解决了假冒问题。刚刚编写了一个 ASP.net 脚本来使用基于on this oneHttpPostedFile 保存文件,它就像一个魅力。这些文件(可能)是在 IIS 中配置的应用程序池用户下编写的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-10
    • 2011-06-27
    • 1970-01-01
    • 2012-12-25
    • 2014-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多