「RATS」の版間の差分

提供: セキュリティ
移動: 案内検索
(ページの作成:「RATS (Rought Auditing Tool for Security)とは、もともとSecure Software Inc が開発したセキュリティのための監査ツールです。 '''読み方...」)
 
 
行6: 行6:
  
 
== 概要 ==
 
== 概要 ==
[[C]], [[C++]], [[Perl]], [[PHP]], [[Python]], [[Ruby]](もうじき) のソースコードスキャンし、[[バッファオーバーフロー]] や TOCTOU(Time Of Check, Time Of Use) [[競合状態]] などの一般的なセキュリティに関連するプログラミングエラーを見つけます。名前の通り、ラフなソースコード分析を実行するツールです。そのため、すべてのエラーを見つけることも、エラーでないものを見つけることもあります。
+
[[C]], [[C++]], Perl, PHP, [[Python]], Ruby(もうじき) のソースコードスキャンし、[[バッファオーバーフロー]] や TOCTOU(Time Of Check, Time Of Use) [[競合状態]] などの一般的なセキュリティに関連するプログラミングエラーを見つけます。名前の通り、ラフなソースコード分析を実行するツールです。そのため、すべてのエラーを見つけることも、エラーでないものを見つけることもあります。
 
+
 
== インストール ==
 
== インストール ==
 
{{ports|/usr/ports/security/rats|rats}}
 
{{ports|/usr/ports/security/rats|rats}}
 
{{apt|rats}}
 
{{apt|rats}}
 
 
== インストールされたファイル ==
 
== インストールされたファイル ==
 
[[FreeBSD]]の場合です。
 
[[FreeBSD]]の場合です。
行28: 行26:
 
/usr/local/share/doc/rats/README
 
/usr/local/share/doc/rats/README
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
== 使い方 ==
 
== 使い方 ==
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
行72: 行69:
 
                   Display the line of code that caused the problem report
 
                   Display the line of code that caused the problem report
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
== C ==
 
== C ==
 
=== バッファ ===
 
=== バッファ ===
行121: 行117:
 
60869 lines per second
 
60869 lines per second
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
=== strcpy ===
 
=== strcpy ===
 
strcpy は、バッファサイズが指定できないため、strlcpy/strncpy などを利用するべきです。下記のサンプルコードでは、strcpyを使用しているため、ratsが6行目を指摘しています。
 
strcpy は、バッファサイズが指定できないため、strlcpy/strncpy などを利用するべきです。下記のサンプルコードでは、strcpyを使用しているため、ratsが6行目を指摘しています。
行154: 行149:
 
73770 lines per second
 
73770 lines per second
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
== PHP ==
 
== PHP ==
 
=== system ===
 
=== system ===
行181: 行175:
 
54054 lines per second
 
54054 lines per second
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
== 関連項目 ==
 
== 関連項目 ==
* [[静的ソースコード解析]]
+
* 静的ソースコード解析
 
* [https://code.google.com/p/rough-auditing-tool-for-security/ rough-auditing-tool-for-security] Rough Auditing Tool for Security (RATS)
 
* [https://code.google.com/p/rough-auditing-tool-for-security/ rough-auditing-tool-for-security] Rough Auditing Tool for Security (RATS)
<!--
+
<!-- vim: filetype=mediawiki
vim: filetype=mediawiki
+
 
-->
 
-->

2015年9月22日 (火) 18:35時点における最新版

RATS (Rought Auditing Tool for Security)とは、もともとSecure Software Inc が開発したセキュリティのための監査ツールです。

読み方

RATS
らっつ

概要

C, C++, Perl, PHP, Python, Ruby(もうじき) のソースコードスキャンし、バッファオーバーフロー や TOCTOU(Time Of Check, Time Of Use) 競合状態 などの一般的なセキュリティに関連するプログラミングエラーを見つけます。名前の通り、ラフなソースコード分析を実行するツールです。そのため、すべてのエラーを見つけることも、エラーでないものを見つけることもあります。

インストール

FreeBSDにインストールする場合

ports コレクションからインストールする場合

cd /usr/ports/security/rats
sudo make install clean

pkgコマンドでインストールする場合

sudo pkg install rats

portmasterコマンドでインストールする場合

sudo portmaster -y -d /usr/ports/security/rats

portinstallコマンドでインストールする場合

sudo portinstall /usr/ports/security/rats

Ubuntu/Debianにインストールする場合

apt-get コマンドでインストールする場合です。

sudo apt-get install rats

インストールされたファイル

FreeBSDの場合です。

Information for rats-2.3:
 
Files:
/usr/local/man/man1/rats.1.gz
/usr/local/bin/rats
/usr/local/share/rats/rats-c.xml
/usr/local/share/rats/rats-openssl.xml
/usr/local/share/rats/rats-perl.xml
/usr/local/share/rats/rats-php.xml
/usr/local/share/rats/rats-python.xml
/usr/local/share/rats/rats-ruby.xml
/usr/local/share/doc/rats/README

使い方

% rats --help
RATS v2.3 - Rough Auditing Tool for Security
Copyright 2001, 2002 Secure Software Inc
http://www.securesoftware.com
 
usage: rats [-adhilrwxR] [--help] [--database|--db]  name1 name2 ... namen
 
    -a <fun>       report any occurence of function 'fun' in the source file(s)
    -d <filename>  specify an alternate vulnerability database.
    --db
    --database
    -h             display usage information (what you're reading)
    --help
    -i             report functions that accept external input
    --input
    -l <language>  force the specified langauge to be used
    --language <language>
    -r             include references that are not function calls
    --references
    -w <1,2,3>     set warning level (default 2)
    --warning <1,2,3>
    -x             do not load default databases
    -R             don't recurse subdirectories scanning for matching files
    --no-recursion
    --xml          Output in XML.
    --html         Output in HTML.
    --follow-symlinks
                   Follow symlinks and process files found.
    --noheader
                       Don't print initial header in output
    --nofooter
                   Don't show timing information footer at end of analysis
    --quiet
                   Don't print status information regarding what file is being analyzed
    --resultsonly
                   No header, footer, or status information
    --columns
                   Show column number of hte line where the problem occured.
    --context
                   Display the line of code that caused the problem report

C

バッファ

下記のサンプルコートでは、ratsが固定サイズのローカルバッファを指摘しています。

% cat -n buffer_over.c
     1  int main(int argc, char const* argv[])
     2  {
     3          char s[3];
     4          s[1234] = '\0';
     5          return 0;
     6  }% rats  -l c buffer_over.c
Entries in perl database: 33
Entries in ruby database: 46
Entries in python database: 62
Entries in c database: 334
Entries in php database: 55
Analyzing buffer_over.c
buffer_over.c:3: High: fixed size local buffer
Extra care should be taken to ensure that character arrays that are allocated
on the stack are used safely.  They are prime targets for buffer overflow
attacks.
 
Total lines analyzed: 7
Total time 0.000110 seconds
63636 lines per second

ratsでは、配列のサイズを越えているアクセスについて、気づくことができません。

% cat -n string.c
     1  int main(int argc, char const* argv[])
     2  {
     3          char str[] = "hoge";
     4          str[65535] = '\0';
     5          return 0;
     6  }% rats -l c string.c
Entries in perl database: 33
Entries in ruby database: 46
Entries in python database: 62
Entries in c database: 334
Entries in php database: 55
Analyzing string.c
Total lines analyzed: 7
Total time 0.000115 seconds
60869 lines per second

strcpy

strcpy は、バッファサイズが指定できないため、strlcpy/strncpy などを利用するべきです。下記のサンプルコードでは、strcpyを使用しているため、ratsが6行目を指摘しています。

% cat -n strcpy.c
     1  #include <string.h>
     2  int main(int argc, char const* argv[])
     3  {
     4          char dst[3];
     5          char src[] = "foo,bar";
     6          (void) strcpy(dst, src);
     7          return 0;
     8  }% rats -l c strcpy.c
Entries in perl database: 33
Entries in ruby database: 46
Entries in python database: 62
Entries in c database: 334
Entries in php database: 55
Analyzing strcpy.c
strcpy.c:4: High: fixed size local buffer
Extra care should be taken to ensure that character arrays that are allocated
on the stack are used safely.  They are prime targets for buffer overflow
attacks.
 
strcpy.c:6: High: strcpy
Check to be sure that argument 2 passed to this function call will not copy
more data than can be handled, resulting in a buffer overflow.
 
Total lines analyzed: 9
Total time 0.000122 seconds
73770 lines per second

PHP

system

system関数を利用するときに、変数を指定するとratsによって指摘されます。

% cat -n system.php
     1  <?php
     2  //$foo = $_GET['id'];
     3  system ($foo);
     4  system ('echo hoge');
     5  ?>% rats -l php system.php
Entries in perl database: 33
Entries in ruby database: 46
Entries in python database: 62
Entries in c database: 334
Entries in php database: 55
Analyzing system.php
system.php:3: High: system
Argument 1 to this function call should be checked to ensure that it does not
come from an untrusted source without first verifying that it contains nothing
dangerous.
 
Total lines analyzed: 6
Total time 0.000111 seconds
54054 lines per second

関連項目