设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 9328|回复: 3
打印 上一主题 下一主题

Python编程的问题

[复制链接]

21

主题

1

好友

373

积分

中级会员

Rank: 3Rank: 3

跳转到指定楼层
楼主
发表于 2014-9-2 11:27:22 |只看该作者 |倒序浏览
  1. import os
  2. import re
  3. print "Please input the location where you installed the Cygwin:"
  4. print "WARNINING: when you input,please add the '\\' in the back of the location that you input(if your input don't with '\\')"
  5. CYGWIN_HOME=raw_input()
  6. CYGWIN_PASS_DIR=CYGWIN_HOME+"etc\passwd"
  7. if(CYGWIN_HOME==""):
  8.     print "Error!You must enter a directory!!!Exiting"
  9. elif(not os.path.exists(CYGWIN_HOME)):
  10.     print "Error!The path you entered is not existed!!!Exiting"
  11. else:
  12.     f=open(CYGWIN_PASS_DIR,"r")
  13.     con = f.read()
  14.     f.close()
  15.     print con

  16.     con1 = re.sub("Administrator","root",con)
  17.     con2 = re.sub("500","0",con1)
  18.     con3 = re.sub("513","0",con2)
  19.     print con3
  20.     f2 = open(CYGWIN_PASS_DIR, 'w')
  21.     f2.write(con3)
  22.     f2.close()
  23.     if(not os.path.exists(CYGWIN_HOME+"home\\root\")):
  24.         os.mkdir(CYGWIN_HOME+"home\\root\")
  25.       
复制代码
回复

使用道具 举报

21

主题

1

好友

373

积分

中级会员

Rank: 3Rank: 3

沙发
发表于 2014-9-2 11:31:39 |只看该作者
写的一个小程序,用来修改cygwin的passwd,以来获取root权限。但是总是无法正确替换
aa.PNG aaa.PNG aaaa.PNG
回复

使用道具 举报

21

主题

1

好友

373

积分

中级会员

Rank: 3Rank: 3

板凳
发表于 2014-9-2 11:35:05 |只看该作者
现在主要的问题就是总是替换Administrators里的‘Administrator’导致cygwin无法正常运行,再者,如何添加Linux换行符以保持原来文档的正确性?
@Crossin先生
回复

使用道具 举报

21

主题

1

好友

373

积分

中级会员

Rank: 3Rank: 3

地板
发表于 2014-9-2 11:36:42 |只看该作者
@crossin先生
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-4-28 22:58 , Processed in 0.032949 second(s), 30 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部