免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4557 | 回复: 14
打印 上一主题 下一主题

[学习共享] 一个小标点引发一串匪夷所思的问题........ [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-01-03 22:39 |只看该作者 |倒序浏览
本帖最后由 wwr 于 2013-01-05 20:48 编辑

今天在写有关通过shadow文件确定账号是否符合安全标准的脚本:检查账户有效期、检查账户是否设置密码等等。
首先看看这个检查账户有效期的脚本,主要是截取shadow文件第八段,判断账户的过期时间,并echo警告信息。
  1.         while IFS=: read -r f1 f2 f3 f4 f5 f6 f7 f8
  2.           do
  3.           if [ ! -z $f8 ]
  4.           then
  5.         expd="`date -d "1970-01-01+$f8 day" '+%Y-%m-%d'`"
  6.         echo -e "$ATT The account: $f1 will expried at $expd. Please contact your administrator!"
  7.         else echo -e "Checking account $f1 expire date.                $OK"
  8.         fi
  9.         done</etc/shadow
复制代码
我们来执行一下
  1. [root@butter ~]# ./secure.sh
  2. ........
  3. Checking account gopher expire date.            [  OK  ]
  4. ***Attention***    The account: john will expried at 2013-03-04. Please contact your administrator!
  5. Checking account nobody expire date.            [  OK  ]
  6. .....
  7. [root@butter ~]# cat /etc/shadow|grep john
  8. john:$6$hX2SaZv8$TZbICUPboyu2XmVVgYOfDFqvR7sKJeD0N5D2pvmxo3H8bmVl8eCroOLcJYEw6.uvkfQwgg/8b2wV1dvszi79a.:15708:0:99999:7::15768:
复制代码
一切顺利,只要对这个账户设定的密码过期时间,他都能准确的根据第八段时间计算出过期时间。

接着我们来检查账户是否设置密码。其实和上面的脚本几乎一样,唯一改变的是替换成第二字段,只要第二字段不为空我们就认为他是有密码的。脚本内容如下
  1.         while IFS=: read -r f1 f2 f3 f4 f5 f6 f7 f8
  2.           do
  3.           if [ -z $f2 ]
  4.           then
  5.         echo -e "$WAR The account: $f1 has empty password! Please contact your administrator!"
  6.         fi
  7.         else -e "Checking whether the  account $1 has set a password         $OK"
  8.         done</etc/shadow
复制代码
结果执行之后离奇的出现错误
  1. ./secure.sh: line 4: [: too many arguments
复制代码
脚本内容完全是参照检查账户有效期的那个来修改的,而且没有任何错别字。但就是无法解释。
我试图让脚本不进行判断,只输出$f2的内容:
  1. [root@butter ~]# cat secure.sh
  2. while IFS=: read -r f1 f2 f3 f4 f5 f6 f7 f8
  3. do
  4. echo $f2
  5. done</etc/shadow
  6. [root@butter ~]# ./secure.sh
  7. $2y$10$ULX4kt.sVMbsjg0bBwj8FuCF9Exy2GzxnpgbCOZLf.Jtj5FQ7.DjC
  8. ALL_LINE Desktop Documents FLAG UNIQ_LINE autoinst.xml bin inst-sys passwd passwd2 secure.sh st
  9. ALL_LINE Desktop Documents FLAG UNIQ_LINE autoinst.xml bin inst-sys passwd passwd2 secure.sh st
  10. ALL_LINE Desktop Documents FLAG UNIQ_LINE autoinst.xml bin inst-sys passwd passwd2 secure.sh st
  11. ALL_LINE Desktop Documents FLAG UNIQ_LINE autoinst.xml bin inst-sys passwd passwd2 secure.sh st
  12. .............
复制代码
除了第一行显示正常的密码字段以外其余的全是奇怪的内容……

后来我又检查了一下/etc/shadow文件:
  1. [root@butter ~]# cat /etc/shadow
  2. root:$2y$10$ULX4kt.sVMbsjg0bBwj8FuCF9Exy2GzxnpgbCOZLf.Jtj5FQ7.DjC:15705::::::
  3. bin:*:15385::::::
  4. daemon:*:15385::::::
  5. lp:*:15385::::::
  6. mail:*:15385::::::
  7. news:*:15385::::::
  8. uucp:*:15385::::::
  9. games:*:15385::::::
  10. man:*:15385::::::
复制代码
仿佛发现了些什么…………



原来,系统默认账户下的第二字段是星号,表示账户无法登录。
而在脚本中,星号又是一个通配符,刚才通过echo看到的一串奇怪的内容其实是我当前目录下的文件,你现在也可以试试"echo *"输出结果等于"ls"。
恍然大悟了吧!立马重新修改脚本,把刚才判断语句中的$f2给加个双引号。再跑一下。
Bravo!成功了!

  1. [root@butter ~]# cat secure.sh
  2.         while IFS=: read -r f1 f2 f3 f4 f5 f6 f7 f8
  3.         do
  4.         if [ -z "$f2" ]
  5.         then
  6.         echo -e "$WAR The account: $f1 has empty password! Please contact your administrator!"
  7.         else echo -e "Checking the  account $1 has set a password      $OK"
  8.         fi
  9.         done</etc/shadow
  10. [root@butter ~]# ./secure.sh
  11. Checking the  account  root has set a password       [  OK  ]
  12. ..........
  13. ***Warning***    The account: tom has empty password! Please contact your administrator!
  14. ........
  15. [root@butter ~]# cat /etc/shadow|grep tom
  16. tom::15708:0:99999:7:::
复制代码

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
2 [报告]
发表于 2013-01-03 23:07 |只看该作者
本帖最后由 blackold 于 2013-01-03 23:08 编辑

真的很神奇,还有隐藏内容。

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
3 [报告]
发表于 2013-01-03 23:27 |只看该作者
本帖最后由 yinyuemi 于 2013-01-03 23:28 编辑

最匪夷所思的是





























还要回复可见

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
4 [报告]
发表于 2013-01-04 08:49 |只看该作者
最匪夷所思的是shell也能产生匪夷所思的问题

论坛徽章:
3
天蝎座
日期:2013-11-11 10:18:392015年亚洲杯之沙特阿拉伯
日期:2015-04-06 15:51:08CU十四周年纪念徽章
日期:2017-01-07 22:56:29
5 [报告]
发表于 2013-01-04 09:04 |只看该作者
回复 1# wwr


  是不是发现了什么bug ?

论坛徽章:
5
技术图书徽章
日期:2014-04-18 08:52:38午马
日期:2014-04-30 13:28:11摩羯座
日期:2014-11-07 13:34:122015年亚洲杯之日本
日期:2015-03-12 14:01:4915-16赛季CBA联赛之北京
日期:2017-06-28 17:25:56
6 [报告]
发表于 2013-01-04 09:26 |只看该作者
回复可见什么情况

论坛徽章:
60
20周年集字徽章-20	
日期:2020-10-28 14:04:3015-16赛季CBA联赛之北京
日期:2016-07-06 15:42:0715-16赛季CBA联赛之同曦
日期:2016-06-12 10:38:0915-16赛季CBA联赛之佛山
日期:2016-05-27 11:54:56黄金圣斗士
日期:2015-12-02 11:44:35白银圣斗士
日期:2015-11-25 14:32:43白银圣斗士
日期:2015-11-23 12:53:352015亚冠之布里斯班狮吼
日期:2015-10-21 16:55:482015亚冠之首尔
日期:2015-09-01 16:46:052015亚冠之德黑兰石油
日期:2015-08-31 11:39:192015亚冠之萨济拖拉机
日期:2015-08-28 21:06:5315-16赛季CBA联赛之广东
日期:2016-07-12 14:58:53
7 [报告]
发表于 2013-01-04 10:07 |只看该作者
第一次在shell板块看到有隐藏内容的 果然很神奇

论坛徽章:
2
水瓶座
日期:2014-08-20 14:38:50辰龙
日期:2014-09-15 15:49:06
8 [报告]
发表于 2013-01-04 10:27 |只看该作者
我想看看下面是怎么回复的

论坛徽章:
11
CU十二周年纪念徽章
日期:2013-10-24 15:41:342015年辞旧岁徽章
日期:2015-03-03 16:54:15丑牛
日期:2015-01-14 10:36:40技术图书徽章
日期:2015-01-12 15:46:11白羊座
日期:2014-11-14 09:35:36狮子座
日期:2014-10-30 13:18:49巳蛇
日期:2014-10-11 12:52:08子鼠
日期:2014-09-28 14:11:06双鱼座
日期:2014-04-22 13:05:48午马
日期:2014-02-11 17:58:002015年迎新春徽章
日期:2015-03-04 09:55:28
9 [报告]
发表于 2013-01-04 10:53 |只看该作者
奇怪的事情发生了。。。俺来看大牛解答!

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
10 [报告]
发表于 2013-01-04 11:00 |只看该作者
http://catb.org/~esr/faqs/smart-questions.html
Don't rush to claim that you have found a bug

When you are having problems with a piece of software, don't claim you have found a bug unless you are very, very sure of your ground. Hint: unless you can provide a source-code patch that fixes the problem, or a regression test against a previous version that demonstrates incorrect behavior, you are probably not sure enough. This applies to webpages and documentation, too; if you have found a documentation “bug”, you should supply replacement text and which pages it should go on.

Remember, there are many other users that are not experiencing your problem. Otherwise you would have learned about it while reading the documentation and searching the Web (you did do that before complaining, didn't you?). This means that very probably it is you who are doing something wrong, not the software.

The people who wrote the software work very hard to make it work as well as possible. If you claim you have found a bug, you'll be impugning their competence, which may offend some of them even if you are correct. It's especially undiplomatic to yell “bug” in the Subject line.

When asking your question, it is best to write as though you assume you are doing something wrong, even if you are privately pretty sure you have found an actual bug. If there really is a bug, you will hear about it in the answer. Play it so the maintainers will want to apologize to you if the bug is real, rather than so that you will owe them an apology if you have messed up.

@aqbssh
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP