' 11.08.2009
' PwdMd5_05.doc
' PwdMd5_05_11082009.bas
' PwdMd5_05_02_11082009.bas
' PwdMd5_05_03_11082009.bas
'
PRIVATE DECLARE FUNCTION CryptAcquireContext LIB "advapi32.dll" _
ALIAS "CryptAcquireContextA" ( _
BYREF phProv AS LONG, _
BYVAL pszContainer AS STRING, _
BYVAL pszProvider AS STRING, _
BYVAL dwProvType AS LONG, _
BYVAL dwFlags AS LONG) AS LONG
'
PRIVATE DECLARE FUNCTION CryptReleaseContext LIB "advapi32.dll" ( _
BYVAL hProv AS LONG, _
BYVAL dwFlags AS LONG) AS LONG
'
PRIVATE DECLARE FUNCTION CryptCreateHash LIB "advapi32.dll" ( _
BYVAL hProv AS LONG, _
BYVAL Algid AS LONG, _
BYVAL hKey AS LONG, _
BYVAL dwFlags AS LONG, _
BYREF phHash AS LONG) AS LONG
'
PRIVATE DECLARE FUNCTION CryptDestroyHash LIB "advapi32.dll" ( _
BYVAL hHash AS LONG) AS LONG
'
PRIVATE DECLARE FUNCTION CryptHashData LIB "advapi32.dll" ( _
BYVAL hHash AS LONG, _
pbData AS BYTE, _
BYVAL dwDataLen AS LONG, _
BYVAL dwFlags AS LONG) AS LONG
'
PRIVATE DECLARE FUNCTION CryptGetHashParam LIB "advapi32.dll" ( _
BYVAL hHash AS LONG, _
BYVAL dwParam AS LONG, _
pbData AS ANY, _
pdwDataLen AS LONG, _
BYVAL dwFlags AS LONG) AS LONG
'
'
'
'
' PwdMd5_VBA.bas 27.07.2009
'
Public FUNCTION makeDots(sInStr AS STRING) AS STRING
' Unicode Zeichen die >255 (8364 = ¤) sind mit 46(.) ersetzen
'
DIM nTmp AS LONG
DIM sUstr AS STRING
'
sUstr = sInStr
'
FOR nTmp = 1 TO LEN(sUstr)
IF AscW(MID$(sUstr, nTmp, 1)) > 255 THEN
MID$(sUstr, nTmp) = "."
END IF
NEXT nTmp
'
makeDots = sUstr
'
END FUNCTION
'
'
Public FUNCTION InMD5(sTEXT AS STRING) AS STRING
'
DIM AcquireContext AS LONG
DIM HashHandle AS LONG
DIM result AS LONG
DIM LaengeResult AS LONG
DIM Zaehler AS INTEGER
DIM sTmp AS STRING
DIM nTmp1 AS LONG
DIM nTmpLen AS LONG
'
sTmp = StrConv(sTEXT, vbUnicode)
REDIM ByteText(0 TO LEN(sTmp)) AS BYTE
FOR nTmp1 = 0 TO (LEN(sTmp) - 1)
ByteText(nTmp1) = AscB(MID$(sTmp, (1 + nTmp1), 1))
NEXT nTmp1
nTmpLen = LEN(sTmp)
'
'Ermittle Context Handle
result = CryptAcquireContext(AcquireContext, vbNullString, vbNullString, _
1, 0)
IF result = 0 AND Err.LastDllError = &H80090016 THEN
result = CryptAcquireContext(AcquireContext, vbNullString, _
vbNullString, 1, &H8)
END IF
result = CryptCreateHash(AcquireContext, 32771, 0, 0, HashHandle)
'
result = CryptHashData(HashHandle, ByteText(0), nTmpLen, 0)
'
result = CryptGetHashParam(HashHandle, 4, LaengeResult, 4, 0)
REDIM ByteResult(0 TO LaengeResult - 1) AS BYTE
result = CryptGetHashParam(HashHandle, 2, ByteResult(0), LaengeResult, 0)
FOR Zaehler = 0 TO UBOUND(ByteResult)
InMD5 = InMD5 & RIGHT$("0" & HEX$(ByteResult(Zaehler)), 2)
NEXT Zaehler
CryptDestroyHash HashHandle
CryptReleaseContext AcquireContext, 0
'
END FUNCTION
'
'
'
'
Public Function FFSP_Login_Sid(sHost As String, sPassword As String, sSID As String) As Long
'
Dim sMode As String, sLink As String, sFormdata As String
Dim Iswriteaccess As String, sChallenge As String, sResponse As String
Dim sRetHTTPTransferRT As String
Dim sA As String, sB As String, sC As String, sD As String
Dim nPosition As Long, nLength As Long
Dim nPosition2 As Long, nLength2 As Long
Dim nRet1 As Long, nRet2 As Long
'
Static sRetSID As String
'
FFSP_Login_Sid = 0: nRet1 = 0: nRet2 = 0
Iswriteaccess = "": sChallenge = "": sResponse = "": sSID = ""
'
If Trim$(sHost) = "" Or Trim$(sPassword) = "" Then Exit Function ' 04.12.2010
'
sMode = "POST "
sLink = "http://" + sHost + "/cgi-bin/webcm"
'
If sRetSID <> "" Then
sFormdata = "sid=" + sRetSID + "&" + "getpage=../html/login_sid.xml"
Else
sFormdata = "getpage=../html/login_sid.xml"
End If
'
sRetHTTPTransferRT = HTTPTransferRT(sMode, sLink, sFormdata)
'
'iswriteaccess
nPosition = 1: nLength = 0: nPosition2 = 0: nLength2 = 0
'
' login_sid.xml
' sRetHTTPTransferRT = " <SessionInfo> <iswriteaccess> 01 </iswriteaccess> <SID>0000000000000001</SID> <Challenge>6ad690f8</Challenge> </SessionInfo> "
' sRetHTTPTransferRT = " <SessionInfo> <iswriteaccess> 0 </iswriteaccess> <SID>0000000000000000</SID> <Challenge>6ad690f8</Challenge> </SessionInfo> "
sA = sRetHTTPTransferRT
sB = "<iswriteaccess>"
'
nPosition = InStr(nPosition, sA, sB, vbTextCompare)
nLength = Len(sB)
If (nPosition > 0) And (nLength > 0) Then
sD = Mid$(sA, nPosition, nLength)
'
sB = "</iswriteaccess>"
nPosition = nPosition + nLength
nPosition2 = InStr(nPosition, sA, sB, vbTextCompare)
nLength2 = Len(sB)
If (nPosition2 > 0) And (nPosition < nPosition2) And (nLength2 > 0) Then
sD = Mid$(sA, nPosition, (nPosition2 - nPosition) + (nLength2 - Len(sB)))
nRet1 = 1
' sIswriteaccess = Trim$(sD)
sIswriteaccess = sRetainAny(sD, "01")
' If Val(sIswriteaccess) >= 1 Then
If Val("&H" + sIswriteaccess) >= 1 Then
sIswriteaccess = "1"
nRet2 = 1
' ElseIf Val(sIswriteaccess) = 0 Then
ElseIf Val("&H" + sIswriteaccess) = 0 Then
sIswriteaccess = "0"
nRet1 = 2
nRet2 = 2
End If
Else
nRet1 = 2
End If
'
Else
nRet1 = 2
End If
'
'MsgBox Str$(nRet1) + " -1- " + Str$(nRet2) + " " + sD
'
If (nRet1 = 2) And (nRet2 = 2) Then
'
' Challenge
nPosition = 1: nLength = 0: nPosition2 = 0: nLength2 = 0
sA = sRetHTTPTransferRT
sB = "<Challenge>"
'
nPosition = InStr(nPosition, sA, sB, vbTextCompare)
nLength = Len(sB)
If (nPosition > 0) And (nLength > 0) Then
sD = Mid$(sA, nPosition, nLength)
'
sB = "</Challenge>"
nPosition = nPosition + nLength
nPosition2 = InStr(nPosition, sA, sB, vbTextCompare)
nLength2 = Len(sB)
If (nPosition2 > 0) And (nPosition < nPosition2) And (nLength2 > 0) Then
sD = Mid$(sA, nPosition, (nPosition2 - nPosition) + (nLength2 - Len(sB)))
nRet1 = 1
sChallenge = Trim$(sD)
'
sResponse = sChallenge + "-" + LCase$(InMD5(sChallenge + "-" + makeDots(sPassword)))
' 19.08.2011 ' login_sid.xml
sFormdata = "getpage=../html/login_sid.xml"
sFormdata = sFormdata + "&login:command/response=" + sResponse
'
' sFormdata = "getpage=../html/de/menus/menu2.html&login:command/response=" + sResponse
'
sRetHTTPTransferRT = HTTPTransferRT(sMode, sLink, sFormdata)
' Response
'sRetHTTPTransferRT = "<input type=" + Chr$(34) + "hidden" + Chr$(34) + " name=" + Chr$(34) + "sid" + Chr$(34) + " value=" + Chr$(34) + "13e41555bcc92250" + Chr$(34) + " id=" + Chr$(34) + "uiPostSid" + Chr$(34) + ">"
'
If sRetHTTPTransferRT = "" Then ' de/menus/menu2.html 19.08.2011 ' login_sid.xml
'
FFSP_Login_Sid = 0: nRet1 = 0: nRet2 = 0
Iswriteaccess = "": sChallenge = "": sResponse = "": sSID = ""
'
sMode = "POST "
sLink = "http://" + sHost + "/cgi-bin/webcm"
'
If sRetSID <> "" Then
sFormdata = "sid=" + sRetSID + "&" + "getpage=../html/login_sid.xml"
Else
sFormdata = "getpage=../html/login_sid.xml"
End If
'
sRetHTTPTransferRT = HTTPTransferRT(sMode, sLink, sFormdata)
'
'iswriteaccess
nPosition = 1: nLength = 0: nPosition2 = 0: nLength2 = 0
'
sA = sRetHTTPTransferRT
sB = "<iswriteaccess>"
'
nPosition = InStr(nPosition, sA, sB, vbTextCompare)
nLength = Len(sB)
If (nPosition > 0) And (nLength > 0) Then
sD = Mid$(sA, nPosition, nLength)
'
sB = "</iswriteaccess>"
nPosition = nPosition + nLength
nPosition2 = InStr(nPosition, sA, sB, vbTextCompare)
nLength2 = Len(sB)
If (nPosition2 > 0) And (nPosition < nPosition2) And (nLength2 > 0) Then
sD = Mid$(sA, nPosition, (nPosition2 - nPosition) + (nLength2 - Len(sB)))
nRet1 = 1
sIswriteaccess = sRetainAny(sD, "01")
If Val("&H" + sIswriteaccess) >= 1 Then
sIswriteaccess = "1"
nRet2 = 1
ElseIf Val("&H" + sIswriteaccess) = 0 Then
sIswriteaccess = "0"
nRet1 = 2
nRet2 = 2
End If
Else
nRet1 = 2
End If
'
Else
nRet1 = 2
End If
'
If (nRet1 = 2) And (nRet2 = 2) Then
'
' Challenge
nPosition = 1: nLength = 0: nPosition2 = 0: nLength2 = 0
sA = sRetHTTPTransferRT
sB = "<Challenge>"
'
nPosition = InStr(nPosition, sA, sB, vbTextCompare)
nLength = Len(sB)
If (nPosition > 0) And (nLength > 0) Then
sD = Mid$(sA, nPosition, nLength)
'
sB = "</Challenge>"
nPosition = nPosition + nLength
nPosition2 = InStr(nPosition, sA, sB, vbTextCompare)
nLength2 = Len(sB)
If (nPosition2 > 0) And (nPosition < nPosition2) And (nLength2 > 0) Then
sD = Mid$(sA, nPosition, (nPosition2 - nPosition) + (nLength2 - Len(sB)))
nRet1 = 1
sChallenge = Trim$(sD)
'
sResponse = sChallenge + "-" + LCase$(InMD5(sChallenge + "-" + makeDots(sPassword)))
'
' sFormdata = "getpage=../html/login_sid.xml"
' sFormdata = sFormdata + "&login:command/response=" + sResponse
' 19.08.2011 de/menus/menu2.html
sFormdata = "getpage=../html/de/menus/menu2.html&login:command/response=" + sResponse
'
sRetHTTPTransferRT = HTTPTransferRT(sMode, sLink, sFormdata)
' Response
' sRetHTTPTransferRT = " <SessionInfo> <iswriteaccess> 1 </iswriteaccess> <SID>13e41555bcc92250</SID> <Challenge>6ad690f8</Challenge> </SessionInfo> "
'
End If
'
End If
'
End If
'
End If
'
If sRetHTTPTransferRT = "" Then
nRet1 = 2
ElseIf sRetHTTPTransferRT <> "" Then
nRet1 = 1
End If
'
Else
nRet1 = 2
End If
'
Else
nRet1 = 2
End If
'
End If
'
'MsgBox Str$(nRet1) + " -2- " + Str$(nRet2) + " " + sD
'
If nRet1 = 2 Then
'
sFormdata = "getpage=../html/de/menus/menu2.html&login:command/password=" + sPassword
'
sRetHTTPTransferRT = HTTPTransferRT(sMode, sLink, sFormdata)
'
If sRetHTTPTransferRT = "" Then
nRet1 = 1
ElseIf sRetHTTPTransferRT <> "" Then
nRet1 = 2
End If
'
ElseIf nRet1 = 1 Then
'
' SessionID
nPosition = 1: nLength = 0: nPosition2 = 0: nLength2 = 0
sA = sRetHTTPTransferRT
sB = "<SID>"
'
nPosition = InStr(nPosition, sA, sB, vbTextCompare)
nLength = Len(sB)
If (nPosition > 0) And (nLength > 0) Then
sD = Mid$(sA, nPosition, nLength)
'
sB = "</SID>"
nPosition = nPosition + nLength
nPosition2 = InStr(nPosition, sA, sB, vbTextCompare)
nLength2 = Len(sB)
If (nPosition2 > 0) And (nPosition < nPosition2) And (nLength2 > 0) Then
sD = Mid$(sA, nPosition, (nPosition2 - nPosition) + (nLength2 - Len(sB)))
nRet1 = 1
'
' sSID = Trim$(sD)
sSID = LCase$(sRetainAny(sD, "0123456789abcdefABCDEF"))
'
If Val("&H" + sSID) = 0 Then
nRet1 = 2
End If
'
Else
nRet1 = 2
End If
'
Else
nRet1 = 2
End If
'
End If
'
'MsgBox Str$(nRet1) + " -3- " + Str$(nRet2) + " " + sD + " " + sSID
'
If nRet1 = 2 Then
'
' SessionID
nPosition = 1: nLength = 0: nPosition2 = 0: nLength2 = 0
sA = sRetHTTPTransferRT
'
sB = "name=" + Chr$(34) + "sid" + Chr$(34)
'
nPosition = InStr(nPosition, sA, sB, vbTextCompare)
nLength = Len(sB)
If (nPosition > 0) And (nLength > 0) Then
sD = Mid$(sA, nPosition, nLength)
'MsgBox Str$(nPosition2) + " -3a- " + sD
'
sB = "value"
nPosition = nPosition + nLength
nPosition2 = InStr(nPosition, sA, sB, vbTextCompare)
nLength2 = Len(sB)
If (nPosition2 > 0) And (nPosition < nPosition2) And (nLength2 > 0) Then
'
sD = Mid$(sA, nPosition2, nLength2)
'MsgBox Str$(nPosition2) + " -3a- " + sD
sB = Chr$(34)
nLength2 = nLength2 '+ Len(sB) - 1
nPosition = nPosition2 + nLength2
nPosition2 = InStr(nPosition, sA, sB, vbTextCompare)
'
If (nPosition2 > 0) And (nPosition < nPosition2) And (nLength2 > 0) Then
'
sD = Mid$(sA, nPosition2, nLength2)
'MsgBox Str$(nPosition2) + " -3aa- " + sD
sB = Chr$(34)
nLength2 = Len(sB)
nPosition = nPosition2 + nLength2
nPosition2 = InStr(nPosition, sA, sB, vbTextCompare)
'
sD = Mid$(sA, nPosition, (nPosition2 - nPosition) + (nLength2 - Len(sB)))
'MsgBox Str$(nPosition2) + " -3b- " + sD
'
If (nPosition2 > 0) And (nPosition < nPosition2) And (nLength2 > 0) Then
'
nRet1 = 1
'
' sSID = Trim$(sD)
sSID = LCase$(sRetainAny(sD, "0123456789abcdefABCDEF"))
'
If Val("&H" + sSID) = 0 Then
'MsgBox Str$(nPosition2) + " -3c- " + CStr(Val("&H" + sSID))
nRet1 = 2
End If
'
Else
nRet1 = 2
End If
'
Else
nRet1 = 2
End If
'
Else
nRet1 = 2
End If
'
Else
nRet1 = 2
End If
'
End If
'
'MsgBox Str$(nRet1) + " -4- " + Str$(nRet2) + " " + sD + " " + sSID
'
FFSP_Login_Sid = nRet1
'
' Response
' <input type="hidden" name="sid" value="13e41555bcc92250" id="uiPostSid">
' <input type="hidden" name="sid" value="0000000000000000" id="uiPostSid">
'
If nRet1 = 1 Then
sRetSID = sSID
Else
sRetSID = ""
End If
'
End Function
'
'
'
'
FUNCTION HTTPTransferRT(sMode AS STRING, sLink AS STRING, sFormdata AS STRING) AS STRING
' Link: Link zur Webpage
' Mode "Get" oder "Post"
' Microsoft WinHTTP Services, version 5.1
'
DIM nV1 AS LONG, nV2 AS LONG, nV3 AS LONG
DIM sV1 AS STRING, sV2 AS STRING, sV3 AS STRING
DIM nL1 AS LONG, nL2 AS LONG
'
DIM objXMLHTTP AS NEW WinHttp.WinHttpRequest
' Dim objXMLHTTP As New MSXML2.XMLHTTP40
'
sV1 = sMode ' "GET " oder "POST "
sV2 = sLink ' "http://192.168.2.1/html/top_start_passwort.htm"
nV3 = 0
'
objXMLHTTP.Open sV1, sV2, nV3
'
sV1 = "Content-Type"
sV2 = "application/x-www-form-urlencoded"
objXMLHTTP.setRequestHeader sV1, sV2
'
sV1 = sFormdata
objXMLHTTP.SEND sV1
'
' nL1 = objXMLHTTP.readyState ' "Msxml2.XMLHTTP.4.0"
nL2 = objXMLHTTP.Status
'
' If nL1 = 4 And nL2 = 200 Then ' "Msxml2.XMLHTTP.4.0"
' If nL1 = 0 And nL2 = 200 Then ' "WinHttp.WinHttpRequest.5.1"
IF nL1 = 0 AND nL2 = 200 THEN
'
sV1 = objXMLHTTP.responseText
HTTPTransferRT = sV1
'
END IF
'
END FUNCTION
'
'
'
'
FUNCTION FFSP_Logout_Sid(sHost AS STRING, sSID AS STRING) AS LONG
'
DIM sMode AS STRING, sLink AS STRING, sFormdata AS STRING
DIM sRetHTTPTransferRT AS STRING
'
FFSP_Logout_Sid = 0
'
sMode = "POST "
sLink = "http://" + sHost + "/cgi-bin/webcm"
IF LEN(sSID) > 0 THEN
' sFormdata = "getpage=../html/de/menus/menu2.html&sid=" + sSID + "&security:command/logout=&getpage=../html/confirm_logout.html"
sFormdata = "sid=" + sSID + "&security:command/logout=&getpage=../html/confirm_logout.html" ' 21.12.2010 FB 7390
ELSE
' sFormdata = "getpage=../html/de/menus/menu2.html&security:command/logout=" + "beenden"
sFormdata = "getpage=../html/de/menus/menu2.html&security:command/logout=" + "1"
END IF
'
sRetHTTPTransferRT = HTTPTransferRT(sMode, sLink, sFormdata)
'
IF sRetHTTPTransferRT = "" THEN
FFSP_Logout_Sid = 1
ELSEIF sRetHTTPTransferRT <> "" THEN
FFSP_Logout_Sid = 2
END IF
'
END FUNCTION
'
'
'
'
FUNCTION sRetainAny(sStrIn AS STRING, sStrInAny AS STRING) AS STRING
' 10.08.2009
' Liefert alle Zeichen von sStrInAny die in sStrIn enthalten sind zurueck
'
DIM sTmp AS STRING, sTmp1 AS STRING
DIM nTmp AS LONG, nTmp1 AS LONG
DIM sStrInTmp AS STRING, sStrInAnyTmp AS STRING
DIM nStrInTmp AS LONG, nStrInAnyTmp AS LONG
DIM nStrInTmpLen AS LONG, nStrInAnyTmpLen AS LONG
DIM sStrOut AS STRING
'
sStrOut = ""
'
IF sStrIn <> "" THEN
IF sStrInAny <> "" THEN
'
sStrInTmp = sStrIn: sStrInAnyTmp = sStrInAny
nStrInTmpLen = LEN(sStrIn): nStrInAnyTmpLen = LEN(sStrInAny)
'
IF (nStrInTmpLen > 0) AND (nStrInAnyTmpLen > 0) THEN
'
FOR nTmp = 1 TO nStrInTmpLen
'
sTmp = MID$(sStrInTmp, nTmp, 1)
'
FOR nTmp1 = 1 TO nStrInAnyTmpLen
'
sTmp1 = MID$(sStrInAnyTmp, nTmp1, 1)
'
IF sTmp1 = sTmp THEN
sStrOut = sStrOut + sTmp
EXIT FOR
END IF
'
NEXT nTmp1
'
NEXT nTmp
'
IF LEN(sStrOut) > 0 THEN sRetainAny = sStrOut
'
END IF
'
END IF
'
END IF
'
END FUNCTION
'
'