记一次被黑客把数据库黑了的奇妙经历

Posted by zjh on September 14, 2020

论,被黑客把数据库删了,而且没留下任何勒索信息改怎么从gitPage的文档里恢复仅有的备份文件

前言

由于操作失误和不仔细把密码泄露在git的master分支了,导致某个黑客的网络爬虫检测到了,不过我看提交记录,居然28天才扫描到,emmmm,好言归正传不提这个,主要是黑客把我的数据库删的只剩个warning表,

mysql1

由于mysql会有binlog记录所有的mysql操作,我就去查看了binlog的记录,

mysql2

mysql3

发现黑客是把我库删了又新建了库,新建了表,直接把磁盘底层数据给覆盖了。

那就没什么办法,本来是前几天把数据同步到103的,结果我给mysql卸载了,头疼,以后一定定时把数据给备份下来。下面是我卑卑微微从前几天的md文档导入到gitPage里拉下来的文件,现在把他反写回去,主表数据有的恢复,附表却没了(历史记录,收藏,评论,点赞信息等等)

数据恢复,从gitPage的md文档恢复

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.zjhwork.dao.ExceptionDao;
import xyz.zjhwork.entity.Exception;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Describe:
 * Author:zjhChester
 * Date:
 */
@RestController
@Api(tags = "dataBase rebuild ")
public class DbRebuild {
    @Autowired
    private ExceptionDao exceptionDao;

    @GetMapping("/rebuild")
    public int reBuild(){
        List<Exception> list = fileScan();
        list.forEach(l->exceptionDao.insertException(l));

        return list.size();
    }

    public static void main(String[] args) {
        System.out.println(new DbRebuild().fileScan().size());
    }
    private  List<Exception> fileScan(){
        String path = "E:\\workplace\\my_notes\\personal_directory\\posts_";
        File directory = new File(path);
        File[] files = directory.listFiles();
        List<Exception> commentList = new ArrayList<>();
        String content = "";
        String prefix = "";
        String type="";
        String title="";
        String date="";
        String author="";
        String desc = "";
        int index=0;
        for (File f : files) {
            index++;
            try {
               InputStreamReader is = new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8);
//                BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
                String data ;
                StringBuilder sb = new StringBuilder();
//                while((data = br.readLine())!=null)
//                {
//                    sb.append(data);
//                }
                int count =0;
                while ((count=is.read())!=-1){
                    sb.append((char)count);
                }
                title = f.getName().substring(11,f.getName().length()-3);
                date = f.getName().substring(0,10)+" 00:00:00";
                prefix = sb.substring(0,sb.indexOf("#"));
                type = prefix.substring(prefix.indexOf("- ")+2,prefix.length()-3);
                content= sb.substring(sb.indexOf("#"),sb.length());
                author = prefix.substring(prefix.indexOf("author:")+"author:".length(),prefix.indexOf("header-img")).trim();
                desc = content.substring(0,50);
                commentList.add(Exception.builder().title(title).createTime(date).type(type).content(content).author(author).desc(desc).build());
//                br.close();
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return commentList;
    }
}