ElectroChecker.Vuln2Methods.ProcessGet C# (CSharp) Method

ProcessGet() public static method

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

            var state = JsonHelper.ParseJson<Vuln2State>(Convert.FromBase64String(id));

            log.InfoFormat("Looking for Election {0}", state.ElectionId);
            var election = ElectroClient.FindElection(host, Program.PORT, state.Voter.Cookies, state.ElectionId);
            if(election == null)
                throw new ServiceException(ExitCode.CORRUPT, string.Format("Can't find election '{0}'", id));
            log.InfoFormat("Election {0} found", state.ElectionId);

            var gotFlag = ExtractFlag(election, state.PrivateKey, flag.Length);
            if(flag != gotFlag)
                throw new ServiceException(ExitCode.CORRUPT, string.Format("Invalid flag! Got '{0}' instead of expected '{1}'", gotFlag, flag));

            log.Info("Flag found! OK");
            return (int)ExitCode.OK;
        }

Usage Example

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

            GetCommonParams(args, out host, out id, out flag, out vuln);

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