[VBScript]7-zip cmdline werkt niet goed

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • sh4d0wman
  • Registratie: April 2002
  • Laatst online: 17:45

sh4d0wman

Attack | Exploit | Pwn

Topicstarter
Ik heb een probleem met het gebruik van 7Zip in een VBscript. Met de commandline versie (7za.exe) probeer ik een bestand in te pakken. Handmatig via de cli gaat dit goed, tevens lukt het met een constante waarde in mijn script:

VBScript:
1
2
3
4
'MANUAL 7ZIP TEST CODE - WORKS
Set wshShell = CreateObject("WScript.Shell")
iReturn = wshShell.Run("""c:\Program Files\7-Zip\7za.exe"" a ""c:\Documents and Settings\Administrator\Desktop\Files\photo.jpg.7z"" ""c:\Documents and Settings\Administrator\Desktop\Files\photo.jpg""", 0, True)
'END OF 7ZIP TEST CODE.


Het lukt mij echter niet om bestanden in te pakken welke mijn filesearch routine genereert. Ik heb echter geen idee wat hier precies fout gaat, wellicht spatiegebruik / juiste quotes gebruik in WShell.Exec string.
Source en target printen beide het volledige pad inclusief spaties en de juiste bestandsnamen (photo.jpg en photo.jpg.7z

Probleem code:
VBScript:
1
2
3
4
5
6
7
strFile = objFile.Path
strArch = strFile & ".7z"

WScript.Echo "source", strFile
WScript.Echo "target", strArch

set objExec = WShell.Exec(""" & strCommand & "" & a & "" & strArch & "" & "" & strFile & """, 1 ,true)


Voor de volledigheid hierbij mijn complete functie (code voor extensie filtering is weggelaten tbv leesbaarheid):

VBScript:
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
'Recursive Filesearch Subroutine.
'IN - Drive or Path
Sub Search(sPath)

    'Loop through each file in the sPath folder.
    For Each objFile In sPath.Files
    
        strFile = objFile.Path
        strArch = strFile & ".7z"
        strCommand = "c:\program files\7-zip\7za.exe"

        WScript.Echo "source", strFile
        WScript.Echo "target", strArch

        set WShell = CreateObject("WScript.Shell")
        set objExec = WShell.Exec(""" & strCommand & "" & a & "" & strArch & "" & "" & strFile & """, 1 ,true)

        End If
    Next
    
    'Find EACH SUBFOLDER.
    For Each subFolder In sPath.SubFolders
        On Error Resume Next

        'Call the Search subroutine to start the recursive search on EACH SUBFOLDER.
        If Err.number = 0 Then
            Search objFSO.GetFolder(subFolder.Path)
        End If
    Next

End Sub

This signature has been taken down by the Dutch police in the course of an international lawenforcement operation.


Acties:
  • 0 Henk 'm!

  • Brahiewahiewa
  • Registratie: Oktober 2001
  • Laatst online: 30-09-2022

Brahiewahiewa

boelkloedig

Doe eens
code:
1
wscript.echo """ & strCommand & "" & a & "" & strArch & "" & "" & strFile & """
dan zie je denk ik wel wat er misgaat

[ Voor 4% gewijzigd door Brahiewahiewa op 20-02-2013 01:23 ]

QnJhaGlld2FoaWV3YQ==


Acties:
  • 0 Henk 'm!

  • sh4d0wman
  • Registratie: April 2002
  • Laatst online: 17:45

sh4d0wman

Attack | Exploit | Pwn

Topicstarter
Bedankt! Ik ben iets verder maar snap nog niet wat er mis gaat. Mijn nieuwe code:

VBScript:
1
2
3
    Command = """C:\Documents and Settings\Administrator\Desktop\7z-cmd\7za.exe"" a " & chr(34) & strFile & ".zip" & chr(34) & " " & chr(34) & strFile & chr(34) 
        WScript.Echo "Command: " & Command
    RetVal = objShell.Run(Command,0,true)


De WScript echo is als volgt: "C:\Documents and Settings\Administrator\Desktop\7z-cmd\7za.exe" a "C:\test\test file\test.txt.zip" "C:\test\test file\test.txt"

Bovenstaand commando uitvoeren via de CLI levert een zipfile op van de test.txt file met als bestandsnaam test.txt.zip. Echter als ik het script aanroep komt er geen zipfile, ook geen error. Ik mis een debugger :'(
* sh4d0wman speurt verder..

This signature has been taken down by the Dutch police in the course of an international lawenforcement operation.


Acties:
  • 0 Henk 'm!

  • Brahiewahiewa
  • Registratie: Oktober 2001
  • Laatst online: 30-09-2022

Brahiewahiewa

boelkloedig

Bijna goed:
code:
1
Command = chr(34) & "C:\Documents and Settings\Administrator\Desktop\7z-cmd\7za.exe" & chr(34) & " a " &  chr(34) & strFile & ".zip" & chr(34) & " " & chr(34) & strFile & chr(34)

QnJhaGlld2FoaWV3YQ==


  • sh4d0wman
  • Registratie: April 2002
  • Laatst online: 17:45

sh4d0wman

Attack | Exploit | Pwn

Topicstarter
Het werkt, bedankt! Mijn probleem zat in een stukje weggevallen code door al het editten. Hierdoor werd het commando niet daadwerkelijk uitgevoerd. Onderstaande code werkt correct:

VBScript:
1
2
3
4
    Command = chr(34) & "C:\Documents and Settings\Administrator\Desktop\7z-cmd\7za.exe" & chr(34) & " a " &  chr(34) & strFile & ".zip" & chr(34) & " " & chr(34) & strFile & chr(34)
    Set wshShell = CreateObject("WScript.Shell")
    RetVal = wshShell.Run(Command,0,true)
    Set wshShell = Nothing

This signature has been taken down by the Dutch police in the course of an international lawenforcement operation.


  • Brahiewahiewa
  • Registratie: Oktober 2001
  • Laatst online: 30-09-2022

Brahiewahiewa

boelkloedig

offtopic:
vbscript kent ook garbage collection, dus het statement
code:
1
set wshShell = nothing
offtopic:
is overbodig.

QnJhaGlld2FoaWV3YQ==

Pagina: 1