20169216网络攻防技术第三次作业

BAT的简单使用

批处理文件是一个文本文件,这个文件的每一行都是一条DOS命令(大部分时候就好象我们在DOS提示符下执行的命令行一样),可以使用DOS下的Edit或者Windows的记事本(notepad)等任何文本文件编辑工具创建和修改批处理文件。
批处理文件是一种简单的程序,可以通过条件语句(if)和流程控制语句(goto)来控制命令运行的流程,在批处理中也可以使用循环语句(for)来循环执行一条命令。当然,批处理文件的编程能力与C语言等编程语句比起来是十分有限的,也是十分不规范的。批处理的程序语句就是一条条的DOS命令(包括内部命令和外部命令),而批处理的能力主要取决于你所使用的命令。
echo、@、call、pause、rem(小技巧:用::代替rem)是批处理文件最常用的几个命令,我们就从他们开始学起。
echo 表示显示此命令后的字符
echo off 表示在此语句后所有运行的命令都不显示命令行本身
@与echo off相象,但它是加在每个命令行的最前面,表示运行时不显示这一行的命令行(只能影响当前行)。
call 调用另一个批处理文件(如果不用call而直接调用别的批处理文件,那么执行完那个批处理文件后将无法返回当前文件并执行当前文件的后续命令)。
pause 运行此句会暂停批处理的执行并在屏幕上显示Press any key to continue...的提示,等待用户按任意键后继续
rem 表示此命令后的字符为解释行(注释),不执行,只是给自己今后参考用的(相当于程序中的注释)。
下面是我写的一个30秒后关机脚本,之后将其添加到定时计划中去,在每天的凌晨一点执行。
bat文件内容:

shutdown /s /t 60

将其添加到定时计划中去:

C:\Users\asus> schtasks /create /tn shut /tr C:\Users\asus\Desktop\定时关机.bat /sc daily /st 01:00:00

schtasks:

  • /Create 创建新计划任务
  • /Delete 删除计划任务。
  • /Query 显示所有计划任务。
  • /Change 更改计划任务属性。
  • /Run 立即运行计划任务。
  • /End 中止当前正在运行的计划任务。
  • /? 显示帮助/用法。

shell的简单使用

shell脚本和bat脚本基本的是相同的。
下面是sh的定时任务crontab的简单介绍:
添加定时任务:crontab -e进去文件编辑

* * * * * sh脚本文件or命令

分钟(0-59) 小時(0-23) 日期(1-31) 月份(1-12) 星期(0-6)
除了数字还有几个个特殊的符号就是"*"、"/"和"-"、","。
代表所有的取值范围内的数字;"/"代表每的意思,"/5"表示每5个单位;"-"代表从某个数字到某个数字;","分开几个离散的数字。
写一个sh脚本输出当前的日期和时间

#! /bin/sh
echo $(date +"%Y-%m-%d %H:%M:%S") >>/root/time.txt

将其添加到定时任务中


root@localhost:~# crontab -e

  nano 2.6.3                                                       文件: /tmp/crontab.Te17Z1/crontab                                                               

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

*/1 * * * * /root/time.sh

执行结果:

root@localhost:~# nano time.txt
  nano 2.6.3                                                                文件: time.txt                                                                         


2017-03-16 16:34:18
2017-03-16 16:45:01
2017-03-16 16:46:01

因为我使用的ssh连接,需要每次开机都要打开ssh服务。将ssh服务设置成开机自己启动:

root@localhost:~# nano /etc/rc.local
  nano 2.6.3                                                              文件: /etc/rc.local                                                                      

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
service ssh start
exit 0

当然也可以添加sh脚本文件

sh +sh脚本文件

nmap的应用

1.扫描一个网络段所有在线的主机。(攻击机是kali在192.168.200.0/24网段;靶机是Metasploitable_Ubuntu在192.168.136.0/24网段)

nmap -sP 192.168.136.128

不知道为什么,测试结果显示256个主机在线?而单独ping时,只有真正主机128、129两个ip返回信息,别的都不返回信息。
而是用

root@localhost:~# fping -a -s -r 1 -g 192.168.136.1 192.168.136.255

扫描结果正确,结果如下:(...128,...129分别是Metasploitable的xin和linux版本)

root@localhost:~# fping -a -s -r 1 -g 192.168.136.1 192.168.136.255
192.168.136.1
192.168.136.128
192.168.136.129

     255 targets
       3 alive
     252 unreachable
       0 unknown addresses

     252 timeouts (waiting for response)
     507 ICMP Echos sent
       3 ICMP Echo Replies received
       0 other ICMP received

 1.33 ms (min round trip time)
 1.76 ms (avg round trip time)
 2.43 ms (max round trip time)
       13.756 sec (elapsed real time)

2.使用nmap进行主机开放端口扫描

nmap -sS 192.168.136.128

执行结果如下:

root@localhost:~# nmap -sS 192.168.136.128

Starting Nmap 7.25BETA1 ( https://nmap.org ) at 2017-03-17 13:39 CST
Nmap scan report for localhost (192.168.136.128)
Host is up (1.2s latency).
Not shown: 993 closed ports
PORT     STATE    SERVICE
135/tcp  open     msrpc
443/tcp  open     https
445/tcp  open     microsoft-ds
514/tcp  filtered shell
902/tcp  open     iss-realsecure
912/tcp  open     apex-mesh
5357/tcp open     wsdapi

Nmap done: 1 IP address (1 host up) scanned in 8.07 seconds
root@localhost:~# nmap -sS 192.168.136.129

3.使用nmap进行主机网络服务类型的探查

root@localhost:~# nmap -sV 192.168.136.128

Starting Nmap 7.25BETA1 ( https://nmap.org ) at 2017-03-17 13:45 CST
Nmap scan report for 192.168.136.128
Host is up (1.4s latency).
Not shown: 993 closed ports
PORT     STATE    SERVICE         VERSION
135/tcp  open     msrpc           Microsoft Windows RPC
443/tcp  open     ssl/http        VMware VirtualCenter Web service
445/tcp  open     microsoft-ds    Microsoft Windows 7 - 10 microsoft-ds
514/tcp  filtered shell
902/tcp  open     ssl/vmware-auth VMware Authentication Daemon 1.10 (Uses VNC, SOAP)
912/tcp  open     vmware-auth     VMware Authentication Daemon 1.0 (Uses VNC, SOAP)
5357/tcp open     http            Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 36.38 seconds

这个nmap的探测信息有很多的错误
4.使用nmap对主机进行操作系统探测

root@localhost:~# nmap -O 192.168.136.128

Starting Nmap 7.25BETA1 ( https://nmap.org ) at 2017-03-17 14:24 CST
Nmap scan report for localhost (192.168.136.128)
Host is up (0.37s latency).
Not shown: 993 closed ports
PORT     STATE    SERVICE
135/tcp  open     msrpc
443/tcp  open     https
445/tcp  open     microsoft-ds
514/tcp  filtered shell
902/tcp  open     iss-realsecure
912/tcp  open     apex-mesh
5357/tcp open     wsdapi
Device type: general purpose
Running: Microsoft Windows 7|2012|XP
OS CPE: cpe:/o:microsoft:windows_7 cpe:/o:microsoft:windows_server_2012 cpe:/o:microsoft:windows_xp::sp3
OS details: Microsoft Windows 7 or Windows Server 2012, Microsoft Windows XP SP3

OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 19.42 seconds

这个对目标主机的操作系统的探测又出现了错误。
这周的学习大致就是这些。nessus的安装和openvas还没有安装完成,会尽快安装好。

posted @ 2017-03-16 11:24  qing蒸yu  阅读(769)  评论(2编辑  收藏  举报