Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Scratz en 22 Agosto 2007, 17:30 pm



Título: Descargar archivos creandolos de de forma oculta.
Publicado por: Scratz en 22 Agosto 2007, 17:30 pm
Holas.

Estoy usando Inet para descargar un archivo y este es mi código:

Código:
    Dim Mx() As Byte

    Mx() = intCon.OpenURL(file6.Text, 1)
    Open Environ("ProgramFiles") & "\Activision\Call of Duty 2\" & "wallhack.ini" For Binary Access Write As #1
    Put #1, , Mx() 'file is saving
    Close #1 ' #1 : file is closing
   

Lo que me gustaría es que el archivo se crease oculto (con el atributo "Oculto", como si fuesemos a Propiedades). ¿Cómo lo puedo hacer? ¿Tengo que modificar el "Write As #1" por otro número?

Gracias.


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: ~~ en 22 Agosto 2007, 17:37 pm
No, el 1 solo es el canal. Lo mejor es q lo guardes y una vez guardado modifikes sus propiedades. Si no te kieres liar mucho utiliza las funciones del MS-DOS...


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: kichan en 22 Agosto 2007, 17:45 pm
con la api SetAtributtes (creo que la escribi bien..xD)  puedes darle en teoria artributos aun archivo.
como dejarlo oculto..de lectura...y demaces..pero no se asta que punto esa api haga lo qye realmente dicen que hace..


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: Scratz en 22 Agosto 2007, 17:59 pm
Gracias a los dos. Estoy Googleando pero solo encuentro ejemplos de VB.NET =/


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: kichan en 22 Agosto 2007, 18:04 pm
una vez que lo bajas y lo cierras (todo desde tu codigo claro)
pones dicha api..SetFileAtributtes   (ahora si la escribi bien)
solo busca la definiciones en google para VB 6 y la sintaxis correcta y ya..
es mas o menos asi

Código:
SetFileAttributes("nombredearchivo.exe",File_ATTRIBUTE_NORMAL,......etc...
algo asi...
ojo es solo un ejemplo de como puede ser


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: ~~ en 22 Agosto 2007, 18:12 pm
SetFileAttributes segun la pai guide:

Citar
Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long

Parameters:

· lpFileName
Points to a string that specifies the name of the file whose attributes are to be set.
Windows 95: This string must not exceed MAX_PATH characters.
Windows NT: There is a default string size limit for paths of MAX_PATH characters. This limit is related to how the SetFileAttributes function parses paths. An application can transcend this limit and send in paths longer than MAX_PATH characters by calling the wide (W) version of SetFileAttributes and prepending “\\?\” to the path. The “\\?\” tells the function to turn off path parsing; it lets paths longer than MAX_PATH be used with SetFileAttributesW. This also works with UNC names. The “\\?\” is ignored as part of the path. For example, “\\?\C:\myworld\private” is seen as “C:\myworld\private”, and “\\?\UNC\wow\hotstuff\coolapps” is seen as “\\wow\hotstuff\coolapps”.

· dwFileAttributes
Specifies the file attributes to set for the file. This parameter can be a combination of the following values. However, all other values override FILE_ATTRIBUTE_NORMAL.
FILE_ATTRIBUTE_ARCHIVE
 The file is an archive file. Applications use this value to mark files for backup or removal.
FILE_ATTRIBUTE_HIDDEN
 The file is hidden. It is not included in an ordinary directory listing.
FILE_ATTRIBUTE_NORMAL
 The file has no other attributes set. This value is valid only if used alone.
FILE_ATTRIBUTE_OFFLINE
 The data of the file is not immediately available. Indicates that the file data has been physically moved to offline storage.
FILE_ATTRIBUTE_READONLY
 The file is read-only. Applications can read the file but cannot write to it or delete it.
FILE_ATTRIBUTE_SYSTEM
 The file is part of the operating system or is used exclusively by it.
FILE_ATTRIBUTE_TEMPORARY
 The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.

Return Values:

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Y el ejemplo:

Código
  1. Const MOVEFILE_REPLACE_EXISTING = &H1
  2. Const FILE_ATTRIBUTE_TEMPORARY = &H100
  3. Const FILE_BEGIN = 0
  4. Const FILE_SHARE_READ = &H1
  5. Const FILE_SHARE_WRITE = &H2
  6. Const CREATE_NEW = 1
  7. Const OPEN_EXISTING = 3
  8. Const GENERIC_READ = &H80000000
  9. Const GENERIC_WRITE = &H40000000
  10. Private Declare Function SetVolumeLabel Lib "kernel32" Alias "SetVolumeLabelA" (ByVal lpRootPathName As String, ByVal lpVolumeName As String) As Long
  11. Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
  12. Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
  13. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  14. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  15. Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
  16. Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
  17. Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
  18. Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
  19. Private Declare Function MoveFileEx Lib "kernel32" Alias "MoveFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal dwFlags As Long) As Long
  20. Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
  21. Private Sub Form_Load()
  22.    'KPD-Team 1998
  23.    'URL: http://www.allapi.net/
  24.    'E-Mail: KPDTeam@Allapi.net
  25.    Dim sSave As String, hOrgFile As Long, hNewFile As Long, bBytes() As Byte
  26.    Dim sTemp As String, nSize As Long, Ret As Long
  27.    'Ask for a new volume label
  28.    sSave = InputBox("Please enter a new volume label for drive C:\" + vbCrLf + " (if you don't want to change it, leave the textbox blank)")
  29.    If sSave <> "" Then
  30.        SetVolumeLabel "C:\", sSave
  31.    End If
  32.  
  33.    'Create a buffer
  34.    sTemp = String(260, 0)
  35.    'Get a temporary filename
  36.    GetTempFileName "C:\", "KPD", 0, sTemp
  37.    'Remove all the unnecessary chr$(0)'s
  38.    sTemp = Left$(sTemp, InStr(1, sTemp, Chr$(0)) - 1)
  39.    'Set the file attributes
  40.    SetFileAttributes sTemp, FILE_ATTRIBUTE_TEMPORARY
  41.    'Open the files
  42.    hNewFile = CreateFile(sTemp, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
  43.    hOrgFile = CreateFile("c:\config.sys", GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
  44.  
  45.    'Get the file size
  46.    nSize = GetFileSize(hOrgFile, 0)
  47.    'Set the file pointer
  48.    SetFilePointer hOrgFile, Int(nSize / 2), 0, FILE_BEGIN
  49.    'Create an array of bytes
  50.    ReDim bBytes(1 To nSize - Int(nSize / 2)) As Byte
  51.    'Read from the file
  52.    ReadFile hOrgFile, bBytes(1), UBound(bBytes), Ret, ByVal 0&
  53.    'Check for errors
  54.    If Ret <> UBound(bBytes) Then MsgBox "Error reading file ..."
  55.  
  56.    'Write to the file
  57.    WriteFile hNewFile, bBytes(1), UBound(bBytes), Ret, ByVal 0&
  58.    'Check for errors
  59.    If Ret <> UBound(bBytes) Then MsgBox "Error writing file ..."
  60.  
  61.    'Close the files
  62.    CloseHandle hOrgFile
  63.    CloseHandle hNewFile
  64.  
  65.    'Move the file
  66.    MoveFileEx sTemp, "C:\KPDTEST.TST", MOVEFILE_REPLACE_EXISTING
  67.    'Delete the file
  68.    DeleteFile "C:\KPDTEST.TST"
  69.    Unload Me
  70. End Sub

Vamos basicamente es lo q dice kichan:

Código:
SetFileAttributes "nombredearchivo.exe", atributo

Los atributos los puedes ver en la primera cita


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: kichan en 22 Agosto 2007, 18:15 pm
Me parece!!
esa es la pega de un moderador..muy bien..
asi se extraña menos a slasher-k

saludos..


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: Scratz en 22 Agosto 2007, 19:54 pm
;-D Gracias E0N. Ahora tengo un problema de n00b... cuando intento declarar:

Código:
Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long

Me salta un error diciendo...

Citar
No se permiten constantes, cadenas de longitud fija, matrices e instrucciones Declare como miembros Public de módulos de objeto

¿Qué es lo que hago mal? Siempre he tenido problemas con las declaraciones... y es que no entiendo muy bien como funcionan. Quizás tenga que volver a los manuales y leermelos en sério.

Gracias por el aporte =D

-----

Edit:

Por cierto, la variable FILE_ATTRIBUTE_HIDDEN (que es la que me interesa) no viene definida en el ejemplo.

Código:
Const MOVEFILE_REPLACE_EXISTING = &H1
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Const FILE_BEGIN = 0
Const FILE_SHARE_READ = &H1
Const FILE_SHARE_WRITE = &H2
Const CREATE_NEW = 1
Const OPEN_EXISTING = 3
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000

¿Sabeis definirla? No sé como puedo sacar los números que tengo q poner.

Gracias


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: kichan en 22 Agosto 2007, 19:59 pm
puede ser que quizas no metes en un modulo la declaracion bueno hace rato que no programo en VB.
pero pa evitar declararlas existe un archivo qwue se pone en loa carpeta system32.
pero eso debe ser..
que estas poniendo mal dicha declaracion..o no en el lugar indicado


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: HaDeS, - en 22 Agosto 2007, 21:00 pm
Puedes utilizar la funcion SetAttr, sin utilizar ninguna Api.
Para archivos ocultos me parece que es:
Código
  1. Private Sub Command1_Click()
  2. SetAttr "c:\archivo.txt", 34
  3. 'SetAttr Path, Modo
  4. 'Si queres saber el numero que corresponde al modo, juega con la funcion GetAttr. (msgbox getattr("c:\archivo.txt")
  5. 'Tambien visual te da la opcion de escojer el tipo de atributo que le queres dar al archivo, vbHidden creo que seria el numero 34
  6. End Sub
  7.  

Saludos


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: Scratz en 22 Agosto 2007, 22:30 pm
Perfecto, Hades. Sencillo y muy útil. Ahora tengo otra duda... ¿Como mato un archivo oculto? Con la función Kill no puedo... no hace nada.


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: ~~ en 23 Agosto 2007, 01:48 am
Prueva con la api DeleteFile. La descripcion de la api guide:

Citar
Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

· lpFileName
Points to a null-terminated string that specifies the file to be deleted.

Y el ejemplo:

Código
  1. 'This program needs a Dialog box, named CDBox1
  2. '  (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
  3. '   and select Microsoft Common Dialog control)
  4. Private Type FILETIME
  5.    dwLowDateTime As Long
  6.    dwHighDateTime As Long
  7. End Type
  8. Private Type SHFILEOPSTRUCT
  9.    hWnd As Long
  10.    wFunc As Long
  11.    pFrom As String
  12.    pTo As String
  13.    fFlags As Integer
  14.    fAborted As Boolean
  15.    hNameMaps As Long
  16.    sProgress As String
  17. End Type
  18. Private Type SYSTEMTIME
  19.    wYear As Integer
  20.    wMonth As Integer
  21.    wDayOfWeek As Integer
  22.    wDay As Integer
  23.    wHour As Integer
  24.    wMinute As Integer
  25.    wSecond As Integer
  26.    wMilliseconds As Integer
  27. End Type
  28. Private Const GENERIC_WRITE = &H40000000
  29. Private Const OPEN_EXISTING = 3
  30. Private Const FILE_SHARE_READ = &H1
  31. Private Const FILE_SHARE_WRITE = &H2
  32. Private Const FO_DELETE = &H3
  33. Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
  34. Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As Long) As Long
  35. Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
  36. Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
  37. Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
  38. Private Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long
  39. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  40. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  41. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
  42. Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
  43. Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
  44. Private Sub Form_Load()
  45.    'KPD-Team 1998
  46.    'URL: http://www.allapi.net/
  47.    'E-Mail: KPDTeam@Allapi.net
  48.    Dim lngHandle As Long, SHDirOp As SHFILEOPSTRUCT, lngLong As Long
  49.    Dim Ft1 As FILETIME, Ft2 As FILETIME, SysTime As SYSTEMTIME
  50.    'Set the dialog's title
  51.    CDBox.DialogTitle = "Choose a file ..."
  52.    'Raise an error when the user pressed cancel
  53.    CDBox.CancelError = True
  54.    'Show the 'Open File'-dialog
  55.    CDBox.ShowOpen
  56.    'Create a new directory
  57.    CreateDirectory "C:\KPD-Team", ByVal &H0
  58.    'Copy the selected file to our new directory
  59.    CopyFile CDBox.filename, "C:\KPD-Team\" + CDBox.FileTitle, 0
  60.    'Rename the file
  61.    MoveFile "C:\KPD-Team\" + CDBox.FileTitle, "C:\KPD-Team\test.kpd"
  62.    'Open the file
  63.    lngHandle = CreateFile("C:\KPD-Team\test.kpd", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
  64.    'Get the file's size
  65.    MsgBox "The size of the selected file is" + Str$(GetFileSize(lngHandle, lngLong)) + " bytes."
  66.    'Get the fil's time
  67.    GetFileTime lngHandle, Ft1, Ft1, Ft2
  68.    'Convert the file time to the local file time
  69.    FileTimeToLocalFileTime Ft2, Ft1
  70.    'Convert the file time to system file time
  71.    FileTimeToSystemTime Ft1, SysTime
  72.    MsgBox "The selected file was created on" + Str$(SysTime.wMonth) + "/" + LTrim(Str$(SysTime.wDay)) + "/" + LTrim(Str$(SysTime.wYear))
  73.    'Close the file
  74.    CloseHandle lngHandle
  75.    'Delete the file
  76.    DeleteFile "C:\KPD-Team\test.kpd"
  77.    With SHDirOp
  78.        .wFunc = FO_DELETE
  79.        .pFrom = "C:\KPD-Team"
  80.    End With
  81.    'Delete the directory
  82.    SHFileOperation SHDirOp
  83.    End
  84. End Sub

Aunke me parece mucho ejemplo para lo es la api en si xDD

Si tampoco lo consigues borrar con la api siempre puedes cambiar el atributo oculto del archivo (lo dejas en normal) y ya lo borras con kill  :P


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: Scratz en 23 Agosto 2007, 11:55 am
Ehm... sí, mejor lo devuelvo a normal y lo mato con kill. Ese ejemplo da miedo, y seguro que también errores para adaptarlo a mi programa =S


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: Lambda en 23 Agosto 2007, 13:18 pm
simplemente mete la declaracion

Código
  1. Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

y Llamala asi

Código
  1. DeleteFile "archivoaborrar.extension"

no tiene mas misterio


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: kichan en 23 Agosto 2007, 14:24 pm
Por Dios  como tener miedo de utilizar las Apis si gracias a ello el programa se vuelve mas sofisticado por decirlo de algun modo, ademas ganamos en velocidad y no tiene ninguna dificultad declararlas y usuarlas..
lo que pasa, es que estas tan acostumbrado a las malas tecniucas de programacion que enseña el basic..

en fin...

saludos.


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: ~~ en 23 Agosto 2007, 14:37 pm
Ehm... sí, mejor lo devuelvo a normal y lo mato con kill. Ese ejemplo da miedo, y seguro que también errores para adaptarlo a mi programa =S

Jajaja si ya te habia dicho yo q:

Citar
Aunke me parece mucho ejemplo para lo es la api en si xDD

Solo tienes q hacer lo q te dice Lambda, fijate en la explicacion de la api (la primera cita de mi anterior post ;))


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: Scratz en 23 Agosto 2007, 17:48 pm
Gracias a todos. Pero mi miedo a las apis se debe a que...

Código
  1. Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

(http://scratzphoenixcreations.googlepages.com/errordeclaracion.png)

Muchas veces tengo errores con las declaraciones, y no entiendo por qué  :-\

Por eso prefiero ir a lo fácil.


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: ~~ en 23 Agosto 2007, 18:02 pm
Es por q la estas poniendo en un form, asi declarada hiria en un modulo. Para ponerla en un form tienes q hacerlo asi (ya te dejo un ejemplo completo)

Código
  1. Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
  2.  
  3. Private Sub Form_Load()
  4. DeleteFile "C:\hola.txt"
  5. End Sub


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: kichan en 23 Agosto 2007, 18:05 pm
De partida deberias perderle el miedo

esque solo tienes un problema de declaracion,,,
porque no creo que de sintaxis en las apis
siempre es preferible meterlas dentro de un modulo..
no en el general form


Título: Re: Descargar archivos creandolos de de forma oculta.
Publicado por: Scratz en 23 Agosto 2007, 19:15 pm
Es por q la estas poniendo en un form, asi declarada hiria en un modulo. Para ponerla en un form tienes q hacerlo asi (ya te dejo un ejemplo completo)

Código
  1. Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
  2.  
  3. Private Sub Form_Load()
  4. DeleteFile "C:\hola.txt"
  5. End Sub

Bien, gracias. No sabía eso =/ Perdón por mi torpeza. Demos este post por acabado ;P