// translate a host name to a number (add host if needed) HostId HHDFSMasterHostList::getHostNumInternal(const char *hostName) { for (CollIndex i=0; i<getHosts()->entries(); i++) if (strcmp(hostName,getHosts()->at(i)) == 0) return i; char *hostCopy = new char[strlen(hostName)+1]; strcpy(hostCopy, hostName); getHosts()->insertAt(getHosts()->entries(),hostCopy); return getHosts()->entries() - 1; }
unique_ptr<DBClientCursor> SCCFastQueryHandler::handleQuery(const vector<string>& hostStrings, const string& ns, Query query, int nToReturn, int nToSkip, const BSONObj* fieldsToReturn, int queryOptions, int batchSize) { MultiHostQueryOp queryOp(_multiQueryEnv, &_queryThreads); QuerySpec querySpec(ns, query.obj, fieldsToReturn ? *fieldsToReturn : BSONObj(), nToSkip, nToReturn, queryOptions); // TODO: Timeout must be passed down here as well - 30s timeout may not be applicable for // all operations handled. StatusWith<DBClientCursor*> status = queryOp.queryAny(getHosts(hostStrings), querySpec, 30 * 1000); uassertStatusOK(status.getStatus()); unique_ptr<DBClientCursor> cursor(status.getValue()); return cursor; }
// translate a host name to a number (add host if needed) HostId HHDFSMasterHostList::getHostNum(const char *hostName) { if (getHosts()->entries() == 0) initializeWithSeaQuestNodes(); return getHostNumInternal(hostName); }
void main(int argc, char *argv[]){ j = fopen("ips.json","w"); if(argc != 4){ sprintf(json + strlen(json),"{\n\"Error\": \"Faltan o sobran argumentos\"\n}"); fputs(json,j); fclose(j); }else{ char ip[16]; char clase, opcion; int num = atoi(argv[3]); char tipo[10]; f = fopen("red.txt","w"); sprintf(ip,"%s",argv[1]); opcion = argv[2][0]; separaIP(ip); fprintf(f,"Dirección IP: %d.%d.%d.%d\n",IP[0],IP[1],IP[2],IP[3]); clase = getClase(); if(clase == 'A' || clase == 'B' || clase == 'C'){ sprintf(tipo,"%s",getTipo(clase)); fprintf(f,"Tipo: %s\n", tipo); getDiRed(); getBroadcast(0); sprintf(json,"{\n\"Red\": \"%d.%d.%d.%d\",\n\"Clase\": \"%c\",\n\"Primer IP\": \"%d.%d.%d.%d\",\n\"Mascara\": \"%d.%d.%d.%d\",\n\"Broadcast\": \"%d.%d.%d.%d\",\n\"Ultima IP\": \"%d.%d.%d.%d\",\n\"Default Gateway\": \"%d.%d.%d.%d\"",red[0],red[1],red[2],red[3],clase,red[0],red[1],red[2],red[3]+1,mascara[0],mascara[1],mascara[2],mascara[3],broadcast[0],broadcast[1],broadcast[2],broadcast[3],broadcast[0],broadcast[1],broadcast[2],broadcast[3]-1,broadcast[0],broadcast[1],broadcast[2],broadcast[3]-1); imprimeTabla(clase); }else{ fprintf(f,"Clase: %c\n",clase); } switch(opcion){ case 's': validaNumero(bitsNecesarios(num),clase); fprintf(f,"Se crearán %d subredes\n",(int)pow(2,bitsNecesarios(num))); getSubredes(bitsNecesarios(num),clase); break; case 'h': num += 2; getHosts(bitsNecesarios(num),clase); break; case '-': sprintf(json+strlen(json),"\n"); fputs(json,j); break; default: sprintf(json + strlen(json),"{\n\"Error\": \"Argumento inválido\"\n}"); fputs(json,j); fclose(j); exit(0); } fclose(f); strcat(json,"}"); fputs(json,j);; fclose(j); } }
NABoolean HHDFSMasterHostList::initializeWithSeaQuestNodes() { NABoolean result = FALSE; FILE *pp; NAString fakeNodeNames = ActiveSchemaDB()->getDefaults().getValue(HIVE_USE_FAKE_SQ_NODE_NAMES); if (fakeNodeNames.length() <= 1) { // execute the command "sqshell -c node" and open a pipe to the output of this command. pp = popen("sqshell -c node", "r"); if (pp != NULL) { // we want to add all the nodes returned by sqshell such that their HostIds // assigned here in class HHDFSMasterHostList matches their SeaQuest host number HostId nextHostId = getHosts()->entries(); while (1) { char *line; char buf[1000]; line = fgets(buf, sizeof buf, pp); if (line == NULL) { // if we inserted anything without encountering an error, consider that success numSQNodes_ = getHosts()->entries(); result = (numSQNodes_ > 0); break; } char *nodeNum = strstr(line, "Node["); if (nodeNum) { nodeNum += 5; // skip the matched text int nodeId = atoi(nodeNum); if (nodeId != nextHostId) break; // out-of-sequence host ids are not supported char *nodeName = strstr(nodeNum, "="); if (nodeName == NULL) break; // expecting "=" sign in the sqshell output nodeName++; char *nodeEnd = strstr(nodeName, ","); if (nodeEnd == NULL) break; // couldn't find the end of the node name *nodeEnd = 0; // resolve the found name to make it a fully qualified DNS name, // like HDFS also uses it struct hostent * h = gethostbyname(nodeName); if (h) nodeName = h->h_name; HostId checkId = getHostNumInternal(nodeName); if (checkId != nodeId) if (checkId > nodeId) break; // something must have gone wrong, this should not happen else { // checkId < nodeId, this can happen if we have duplicate // node ids. In this case, insert a dummy node to take up the // number, so we stay in sync sprintf(buf, "dummy.node.%d.nosite.com", nodeId); HostId checkId2 = getHostNumInternal(buf); if (checkId2 != nodeId) break; // again, not expecting to get here // remember that we mave multiple SQ nodes // on the same physical node hasVirtualSQNodes_ = TRUE; } nextHostId++; } } pclose(pp); } } else { // seed the host name list with fake SQ node names from the CQD insted const char delim = ','; const char *nodeStart = fakeNodeNames; const char *nodeEnd; do { // this is debug code, no error check, no blanks in this string!!! char buf[500]; nodeEnd = strchrnul(nodeStart, delim); strncpy(buf, nodeStart, nodeEnd-nodeStart); getHostNumInternal(buf); nodeStart = nodeEnd+1; } while (*nodeEnd != 0); numSQNodes_ = getHosts()->entries(); result = (numSQNodes_ > 0); } return result; }
// get host name from host number const char * HHDFSMasterHostList::getHostName(HostId hostNum) { return getHosts()->at(hostNum); }
/* ** This one returns the configuration, useful for displaying information before running an attack. ** Basically just grabs information from the getters and puts it together in a more stylish way for terminal or log output. ** ** @return std::string */ std::string panda::getConfiguration() { std::string config; config = "\n\n+--------------[AngryPanda Configuration]---------------\n|\n|\tHosts: \t\t" + stringify(getHosts()); config += "\n|\tTarget count:\t\t" + stringify(getHostCount()); config += "\n|\tPort:\t\t" + stringify(getPort()); config += "\n|\tMode:\t\t" + stringify(getMode()); config += "\n|\tTries/IP:\t" + stringify(getTries()); if(arguments.mode) { config += "\n|\tWordlist:\t" + stringify(getWordlist()); config += "\n|\tUsername:\t" + stringify(getUsername()); } else { config += "\n|\tUsername:\t" + stringify(getUsername()); config += "\n|\tPassword:\t" + stringify(getPassword()); } return config; }