ElectroChecker.Vuln2Methods.ProcessPut C# (CSharp) Method

ProcessPut() public static method

public static ProcessPut ( string host, string id, string flag ) : int
host string
id string
flag string
return int
        public static int ProcessPut(string host, string id, string flag)
        {
            log.Info("Processing Vuln2.Put");

            var candidateUsers = RegisterCandidates(host, flag.Distinct().Select(c => UsersManager.GenUser(null, c.ToString())).OrderBy(user => user.Login).ToArray());

            var election = StartElection(host, candidateUsers[0], false, nominateTimeInSec, voteTimeInSec);
            var privateKey = election.PrivateKeyForCandidates;

            var sw = Stopwatch.StartNew();
            election = NominateUsers(host, election, candidateUsers.Skip(1).ToArray());
            sw.Stop();

            var tts = nominateTimeInSec * 1000 - sw.ElapsedMilliseconds;
            if(tts > 0)
            {
                log.InfoFormat("Sleeping for {0}ms before voting (nomination duration is {1}s)", tts, nominateTimeInSec);
                Thread.Sleep((int) tts);
            }

            var votes = GenVotes(flag, election);

            var voters = RegisterVoters(host, votes, candidateUsers);

            log.InfoFormat("Voting by {0} voters", voters.Length);
            foreach(var voter in voters)
                ElectroClient.Vote(host, Program.PORT, voter.Key.Cookies, election.Id, HomoCrypto.EncryptVector(voter.Value, election.PublicKey));
            log.Info("Voted");

            var state = new Vuln2State
            {
                ElectionId = election.Id.ToString(),
                Voter = voters[0].Key,
                PrivateKey = privateKey
            };

            log.Info("Flag put");
            Console.Out.WriteLine(Convert.ToBase64String(Encoding.UTF8.GetBytes(state.ToJsonString())));
            return (int) ExitCode.OK;
        }

Usage Example

Example #1
0
        private static int ProcessPut(string[] args)
        {
            string host, id, flag;
            int    vuln;

            int ec;

            if ((ec = GetCommonParams(args, out host, out id, out flag, out vuln)) != (int)ExitCode.OK)
            {
                return(ec);
            }

            if (vuln == 1)
            {
                return(Vuln1Methods.ProcessPut(host, id, flag));
            }
            else if (vuln == 2)
            {
                return(Vuln2Methods.ProcessPut(host, id, flag));
            }
            else
            {
                return(ExitWithMessage(ExitCode.CHECKER_ERROR, string.Format("Unsupported vuln #{0}", vuln)));
            }
        }