[原创]编程之修改文件修改时间的程序
编程之修改文件修改时间的程序gxm
一次偶然挂马。用了好多IIS挂马,ISAPI,文件重定向挂马方法,不久后被管理员KILL。无奈只能用原始方法,因此,修改文件修改时间是必要的,管理员也因此用这个查。虽然海洋ASP木马上有这个功能,但经过测试,有的时候不行(原因不明,估计是权限问题),所以自己尝试写了这么个软件,代码如下:
#include "stdafx.h"
#include "windows.h"
#include "iostream.h"
#include "stdlib.h"
int main(int argc, char* argv[])
{
if (argc == 8)
{
FILETIME ft,ft1;
SYSTEMTIME systime;
int gxm,gxm1,gxm2,gxm3,gxm4,gxm5;
gxm=atoi(argv[7]);
gxm=gxm - 1;
gxm1=atoi(argv[2]);
gxm2=atoi(argv[3]);
gxm3=atoi(argv[4]);
gxm4=atoi(argv[5]);
gxm5=atoi(argv[6]);
systime.wYear = gxm1;
systime.wMonth = gxm2;
systime.wDay = gxm3;
systime.wHour = gxm4;
systime.wMinute = gxm5;
systime.wSecond = gxm; //想要改变秒,必须要少一位
SystemTimeToFileTime(&systime, &ft);
LocalFileTimeToFileTime(&ft,&ft1); //把时间转换UTC
HANDLE hFile;
hFile = CreateFile(argv[1], GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ| FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile== INVALID_HANDLE_VALUE)
{
printf("open't the file[!]...................................error\n");
}
SetFileTime(hFile, (LPFILETIME) NULL, (LPFILETIME) NULL, &ft1);
CloseHandle(hFile);
printf("changed[!]...................................OK\n");
return 0;
}
printf("GXM修改文件最后修改日期工具\n");
cout << "文件使用方法为:"<<endl;
cout << "\t" << argv[0] << " path year month Day Hour Minute Second"<<endl;
return 0;
}
xp sp2 vc++6.0环境下编译成功,2k 2003 xp测试软件效果成功。需要运行程序权限:本菜在administrator下运行的,其他的没有测试。估计guest权限不行 调试没有成功额,,,不知道是什么原因,如果不支持MFC的话就是找不到stdafx.h,如果用MFC的时候就还是出错。、
唉。。偶菜哦。
嗯。。现在好了。。好象是我的VC出问题了、、、
[[i] 本帖最后由 yaergege 于 2008-5-14 08:50 编辑 [/i]] 在学C++.但还没学VC++.......有点看不懂!:cry: :cry: //设置文件时间
procedure setTime(srcFile,destFile:PChar);
var
hFileOld,hFileNew :THandle;
CreationTime, LastAccessTime, LastWriteTime :PFileTime;
begin
hFileOld :=createFile(srcFile,generic_read,file_share_read,nil,
open_existing,FILE_ATTRIBUTE_NORMAL,Cardinal(nil));
if (hFileOld=INVALID_HANDLE_VALUE) then exit;
hFileNew :=createFile(destFile,generic_write,file_share_write,nil,
open_existing,FILE_ATTRIBUTE_NORMAL,Cardinal(nil));
if (hFileNew=INVALID_HANDLE_VALUE) then exit;
GetMem(CreationTime,SizeOf(TFileTime));
GetMem(LastAccessTime,SizeOf(TFileTime));
GetMem(LastWriteTime,SizeOf(TFileTime));
GetFileTime(hFileOld,CreationTime,LastAccessTime,LastWriteTime);
SetFileTime(hFileNew,CreationTime,LastAccessTime,LastWriteTime);
FreeMem(CreationTime);
FreeMem(LastAccesstime);
FreeMem(LastWriteTime);
CloseHandle(hFileNew);
CloseHandle(hFileOld);
end; 楼主的可以自定义文件时间,这样自主性比较大。不过有时候就是麻烦了点。
偶也贴上一个,是“借用”别的文件的时间。。。参数比较简单点。。
CopyFileTime.asm[code]
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 命令行下复制文件的时间
; By taiwansee
; 2008.05.17
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hOutputBuf DWORD ?
lpCreationTime FILETIME <>
lpLastAccessTime FILETIME <>
lpLastWriteTime FILETIME <>
.data
szUSEAGE BYTE 0dh,0ah
BYTE '*************************************************************',0dh,0ah
BYTE '* Copy File Time *',0dh,0ah
BYTE '* By taiwansee 2008.05.17 *',0dh,0ah
BYTE '*************************************************************',0dh,0ah
BYTE '-Tested on: Windows 2000/XP/2003',0dh,0ah
BYTE '-USEAGE: %s Source.asp Destination.asp ',0dh,0ah,0
szOpenSourceFileErr BYTE 'Open Source File Failed!',0dh,0ah,0
szOpenDesFileErr BYTE 'Open Destination File Failed!',0dh,0ah,0
szGetSourceFileTimeErr BYTE 'Get Source File Time Failed!',0dh,0ah,0
szSetDesFileTimeErr BYTE 'Set Destination File Time Failed!',0dh,0ah,0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
include _CmdLine.asm
;********************************************************
; 显示出错信息
;********************************************************
_ShowError proc _lpError
local @dwWritten:dword,\
@szBuffer[MAX_PATH]:byte,\
@dwBufSize:dword,\
@hOutputBuf:dword
pushad
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov @hOutputBuf,eax
invoke lstrlen,_lpError
mov @dwBufSize,eax
invoke WriteConsole,@hOutputBuf,addr @szBuffer,@dwBufSize,addr @dwWritten,NULL
popad
ret
_ShowError endp
;********************************************************
; 显示帮助信息
;********************************************************
_ShowUSEAGE proc
local @lpInputBuf:dword,\
@szBuffer[MAX_PATH*2]:byte,\
@szProcessNameBuf[MAX_PATH]:byte,\
@dwWritten:dword,\
@dwBufSize:dword
pushad
invoke _argv,0,addr @szProcessNameBuf,sizeof @szProcessNameBuf
invoke wsprintf,addr @szBuffer,offset szUSEAGE,addr @szProcessNameBuf
invoke lstrlen,addr @szBuffer
mov @dwBufSize,eax
invoke WriteConsole,hOutputBuf,addr @szBuffer,@dwBufSize,addr @dwWritten,NULL
popad
ret
_ShowUSEAGE endp
;********************************************************
; 主程序
;********************************************************
_WinMain proc
local @szSourceFile[MAX_PATH]:byte,\
@szDestinationFile[MAX_PATH]:byte,\
@hDestinationFile:dword,\
@hSourceFile:dword
;********************************************************************
; 获取命令行参数
;********************************************************************
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hOutputBuf,eax
;检查输入的参数个数是否正确
invoke _argc ;获取参数个数
.if eax!=3
call _ShowUSEAGE
jmp exit
.endif
invoke _argv,1,addr @szSourceFile,sizeof @szSourceFile
invoke _argv,2,addr @szDestinationFile,sizeof @szSourceFile
;********************************************************************
; 打开文件
;********************************************************************
;打开被拷贝时间的文件。。。。
invoke CreateFile,addr @szSourceFile,GENERIC_READ,\
FILE_SHARE_READ,NULL,OPEN_EXISTING,\
FILE_ATTRIBUTE_NORMAL,NULL
.if eax == INVALID_HANDLE_VALUE
invoke _ShowError,offset szOpenSourceFileErr
jmp exit
.endif
mov @hSourceFile,eax
;打开目标文件。。。。
invoke CreateFile,addr @szDestinationFile,GENERIC_READ or GENERIC_WRITE,\
FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,OPEN_EXISTING,\
FILE_ATTRIBUTE_NORMAL,NULL
.if eax == INVALID_HANDLE_VALUE
invoke _ShowError,offset szOpenDesFileErr
jmp exit
.endif
mov @hDestinationFile,eax
;********************************************************************
; 设置文件时间
;********************************************************************
;获取文件时间
invoke GetFileTime,@hSourceFile,offset lpCreationTime,\
offset lpLastAccessTime,\
offset lpLastWriteTime
.if eax==0
invoke _ShowError,offset szGetSourceFileTimeErr
jmp exit
.endif
;设置文件时间
invoke SetFileTime,@hDestinationFile,offset lpCreationTime,\
offset lpLastAccessTime,\
offset lpLastWriteTime
.if eax==0
invoke _ShowError,offset szSetDesFileTimeErr
jmp exit
.endif
exit:
ret
_WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
call _WinMain
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
[/code]_CmdLine.asm[code];>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; _CmdLine.asm
; 命令行参数分析的通用子程序
; 功能:
; _argc ---> 对命令行参数进行数量统计
; _argv ---> 取某个命令行参数;
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
CHAR_BLANK equ 20h ;定义空格
CHAR_DELI equ '"' ;定义分隔符
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 取命令行参数个数 (arg count)
; 参数个数必定大于等于 1, 参数 1 为当前执行文件名
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_argc proc
local @dwArgc
pushad
mov @dwArgc,0
invoke GetCommandLine
mov esi,eax
cld
_argc_loop:
;********************************************************************
; 忽略参数之间的空格
;********************************************************************
lodsb
or al,al
jz _argc_end
cmp al,CHAR_BLANK
jz _argc_loop
;********************************************************************
; 一个参数开始
;********************************************************************
dec esi
inc @dwArgc
_argc_loop1:
lodsb
or al,al
jz _argc_end
cmp al,CHAR_BLANK
jz _argc_loop ;参数结束
cmp al,CHAR_DELI
jnz _argc_loop1 ;继续处理参数内容
;********************************************************************
; 如果一个参数中的一部分有空格,则用 " " 包括
;********************************************************************
@@:
lodsb
or al,al
jz _argc_end
cmp al,CHAR_DELI
jnz @B
jmp _argc_loop1
_argc_end:
popad
mov eax,@dwArgc
ret
_argc endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 取指定位置的命令行参数
; argv 0 = 执行文件名
; argv 1 = 参数1 ...
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_argv proc _dwArgv,_lpReturn,_dwSize
local @dwArgv,@dwFlag
pushad
inc _dwArgv
mov @dwArgv,0
mov edi,_lpReturn
invoke GetCommandLine
mov esi,eax
cld
_argv_loop:
;********************************************************************
; 忽略参数之间的空格
;********************************************************************
lodsb
or al,al
jz _argv_end
cmp al,CHAR_BLANK
jz _argv_loop
;********************************************************************
; 一个参数开始
; 如果和要求的参数符合,则开始复制到返回缓冲区
;********************************************************************
dec esi
inc @dwArgv
mov @dwFlag,FALSE
mov eax,_dwArgv
cmp eax,@dwArgv
jnz @F
mov @dwFlag,TRUE
@@:
_argv_loop1:
lodsb
or al,al
jz _argv_end
cmp al,CHAR_BLANK
jz _argv_loop ;参数结束
cmp al,CHAR_DELI
jz _argv_loop2
cmp _dwSize,1
jle @F
cmp @dwFlag,TRUE
jne @F
stosb
dec _dwSize
@@:
jmp _argv_loop1 ;继续处理参数内容
_argv_loop2:
lodsb
or al,al
jz _argv_end
cmp al,CHAR_DELI
jz _argv_loop1
cmp _dwSize,1
jle @F
cmp @dwFlag,TRUE
jne @F
stosb
dec _dwSize
@@:
jmp _argv_loop2
_argv_end:
xor al,al
stosb
popad
ret
_argv endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[/code]nmake文件[code]NAME = CopyFileTime
OBJS = $(NAME).obj
LINK_FLAG = /subsystem:console
ML_FLAG = /c /coff
$(NAME).exe: $(OBJS)
Link $(LINK_FLAG) $(OBJS)
.asm.obj:
ml $(ML_FLAG) $<
clean:
del *.obj
del *.exe
del *.res
del *.bak
[/code]附编译好的二进制文件:
[attach]11774[/attach]
[[i] 本帖最后由 taiwansee 于 2008-5-17 20:55 编辑 [/i]] *** 作者被禁止或删除 内容自动屏蔽 ***
页:
[1]
