CTF game Linux file monitoring and recovery shell

Source: Internet
Author: User
Tags diff

Before participating in the CTF competition when the temporary write, there are a lot of shortcomings, but can be used, put it out to share to everyone, hope to help everyone.

Script one: Record the current directory situation

#!/bin/bash
function Getdir () {
for element in ' LS $ '
Do
Dirfile=$1 "/" $element
If [-D $dirfile]
Then
Getdir $dirfile
Else
#将目录结构和大小存为一个临时文件
Echo ' Du-ab $dirfile ' >>/t.txt
#echo $dirfile >>./dir.txt
Fi
Done
}

# Monitored Directories
Dir= "/root/yxy"
Getdir $DIR

function Getdir1 () {
for element in ' LS $ '
Do
Dir_or_file=$1 "/" $element
If [-D $dirfile]
Then
Getdir1 $dirfile
Else
#将目录结构和大小存为一个临时文件
Echo ' Du-ab $dirfile ' >/t1.txt
#echo $dirfile >>./dir.txt
Fi
Done
}

Dir= "/root/yxy"
Getdir1 $DIR
Echo ' diff./t.txt./t1.txt ' >> diff.txt
Rm./t1.txt

Script two: Compare the record of script one, restore the change directory or file
#!bin/bash
function Backup () {
#发生变化的文件, the full path under the backup directory
Backup_dir= "/backup/" ' Tail-n1./diff.txt | awk ' {print $4} ' | Cut-d/F 3-'
#想要恢复的目录, restore files to this directory
Backupfile= ' Cat./diff.txt | awk ' {print $4} ' | cut-d/-f-3 '
for element in ' LS $ '
Do
Dirfile=$1 "/" $element
If [-D $dirfile]
Then
Backup $dirfile
elif [[-F $backup _dir && $backup _dir! = $dirfile]]
Then
CP $backup _dir $backupfile
Else
#要删除的文件
dir= $DIR ' Tail-n1 diff.txt | Awk-f "/" ' {print '/' $NF} '
#这里不能用-r,diff.txt not at the same time, add-R will delete the entire directory
Rm-f $dir
Fi
Done
}

#监控目录
Dir= "/root/yxy"
Backup $DIR


CTF game Linux file monitoring and recovery shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.