在portscanner程序中,我希望成功地写入端口号、扫描者和服务名称的输出。
所以对于每个端口号、scannedby和服务名,我调用下面的parseall例程。

void parseall(int pid, char *scannedby, char *service){  // routine to add port, scannedby and service to xmlfile

  xmlDocPtr doc;  // pointer to parse xml Document

  xmlNodePtr cur = NULL;// node pointer. It interacts with individual node

  xmlAttrPtr attr; char portid[10];

  sprintf (portid,"%d",pid);  // converted int to string

  doc = xmlParseFile(xmlFileName); //parse filename

  cur = xmlDocGetRootElement(doc);   // get rootnode

  addnewportinfotag(cur,doc);  // this routine adds new portid, scannedby and servicename tags to the xmlfile created

  cur = cur->xmlChildrenNode;  //get pointer

  parseport(doc, cur, portid);  // routine to add port to xmlfile

while(cur!=NULL){

if ((!xmlStrcmp(cur->name, (const xmlChar *)"ports"))){

parsehost(doc, cur, scannedby);  // routine to add scanned by to xmlfile

parseservice(doc, cur, service); //routine to add servicename to xmlfile
}

cur = cur->next;

}

xmlSaveFormatFile (xmlFileName, doc, 1);

return;

xmlFreeDoc(doc);

}

代码编译成功,但当我扫描多个端口时,它会给出一个“xml parse error attribute name
重新定义“如下:
     [ Port  ] [ Scanned by] [ Status ] [Service]
     79/tcp     osus          Open      finger
     80/tcp       bt          Open        www
    111/tcp     osus          Open      sunrpc

xmloutput.xml:5: parser error : Attribute portid redefined
<ports protocol="tcp" portid="79" portid="80"><state state="open" reason="vanill
                                             ^
xmloutput.xml:5: parser error : Attribute scannedby redefined
e state="open" reason="vanilla-scan"/><scannedby scannedby="osus" scannedby="bt"
                                                                               ^
xmloutput.xml:5: parser error : Attribute name redefined
"/><scannedby scannedby="osus" scannedby="bt"/><service name="finger" name="www"
                                                                               ^
Segmentation fault

对于单个端口,它可以很好地提供:
<ports protocol="tcp" portid="22"><state state="open" reason="vanilla-scan"/><scannedby scannedby="bt"/><service name="ftp"/></ports></DPScanner>

最佳答案

生成的XML无效。不能在同一个标记上有两个同名属性。
参见Start-Tags, End-Tags, and Empty-Element Tags中的规范:
格式良好约束:唯一Att规范
属性名不能在同一开始标记或空元素标记中出现多次。

10-04 14:17
查看更多